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 ?
Add a comment
|
1 Answer
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');
-
i have create a custom product attribute "sample_attribute" with drop down value i want to add group by in product collection but this gives unknown column how can i add group by in product collection Commented Mar 11, 2021 at 14:09