post by bgeneto on Jul 13, 2023

Hi, John! How difficult is to add a groupBy() method to GCE? It would be a nice companion to defaultOrdering().
Thanks.

post by johnny on Jul 17, 2023

Hello @bgeneto ,

groupBy is a more complicated one since it is changing the number of rows. For now maybe you can create a custom model with any extra more complicated queries. For example a custom model that can look like the example here: setModel | Grocery CRUD - A PHP CRUD Generator Library

<?php 

use GroceryCrud\Core\Model;

class customModel extends Model {

    public function extraWhereStatements($select)
    {
        // please keep in mind that the syntax is from lamina-db
        $select->group('category');
        return $select;
    }

}

As I am not sure if this will work out of the box, maybe you need to create a more complicated customModel as per example here: Custom Model | Grocery CRUD - A PHP CRUD Generator Library

I will have it in mind though maybe to have the groupBy as a future implementation.

Regards
Johnny

1 / 2
Jul 2023