Using groupBy in ListOperation - SELECT list is not in GROUP BY #655
-
Hi, I would like to list a model but aggregate by a column. Is this possible? When I use the following in setupListOperation:
I get the corresponding error as I am not setting columns to select:
Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I think I made it work, after some tinkering I got the desired result with:
Note the select method comes AFTER the groupBy! |
Beta Was this translation helpful? Give feedback.
-
One more detail needed is to disable default ordering by primary key, column id in this case. This is needed to avoid grouping by id column, we dont want to group by id! I've found this issue from 2021 but is closed, When using a custom orderBy:
We get the following SQL error:
This is because the primary key has been added after the custom orderBy()? Is this expected?
Edit, more recent discussion: |
Beta Was this translation helpful? Give feedback.
-
Hey @nrodriguezm To perform similarly, I tried groupBy & order on the demo's monster table. public function setupListOperation(){
$this->crud->groupBy(['email', 'number']);
$this->crud->orderBy('email');
//rest of the code.
} It simply worked... Let me know if I'm missing something. |
Beta Was this translation helpful? Give feedback.
Hey @nrodriguezm
Assuming you are on
MaterialCRUD
andgeneric_code
,container_id
are columns ofmaterials
table.To perform similarly, I tried groupBy & order on the demo's monster table.
It simply worked... Let me know if I'm missing something.