6

I've got a collection from the factory method getCollection(). The problem is that when I use get_class_methods($class) to list all the methods that the collection possesses I can't seem to find one which groups the records in the collection.
I found this How to use group by in magento collection with join query
But I don't have the group() method in my collection class. How can I group by in that case ?

13

You cannot use group directly from the collection.
But each collection has an instance of Zend_Db_Select associated to it. This is the actual query that is going to be executed when the collection is loaded.
So you can use:

$collection = ....
$collection->getSelect()->group('group_field_here');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.