I 开发者_如何学Pythonam using Doctrine 1.2 with Zend Framework. When I fetch a result set as a Doctrine collection, the collection object contains an empty model object of a given type if the returned result-set returned from the DB is empty.
This is quite confusing as we are relying on the count method of Doctrine_Collection to show either a listing of the returned results or an appropriate message when the query returns an empty collection.
Any help will be highly appreciated.
I also thought this was annoying. You want to test for actual results by calling Doctrine_Collection::count()
, such as this scenario that we had:
if ( $collection->count() ) {
// display some widget of the members of Doctrine_Collection
}
The method suggested by yitznewton works for me.
Alternatively, you can test a known field for the first element (0) in the collection.
if ($collection[0]->id) {}
精彩评论