Search code examples
phppropel

How can I get all collections of Propel model?


How can I iterate over all Propel object collections, e.g:

foreach ($obj->getCollections() as $collectionName)
{
    echo "Object's collection $collectionName has " . count($obj->{"get".$collectionName}) . " items<br>\n";
}

Solution

  • You can use the TableMap::getRelations() function. You will find most everything you need to know about Propel introspection in this article: http://propelorm.org/cookbook/runtime-introspection.html

    PS If you only want to know the number of related objects don't go retrieving all of the records - use the count() query function to just return the count.