MySQL 5.7 → group_by error “ SELECT list is not in GROUP BY clause and contains nonaggregated column” when using Phalcon PHP? Try this. (Part II)

So in my last story, I thought that I actually fixed the problem, instead I apparently put a band-aid on a bullet wound. I was missing one key ingredient to my querey, which is a bit tricky in Phalcon’s ORM because their docs don’t really show that you can do this. Think of it like the hidden Animal Style option at In-N-Out. Even though it’s not on the menu, it still exists and you can have it.
TL; DR ? This is the code that
MyModelNameHere::find(['group_by'=>'MIN(your_column_name_here)']);So essentially what you can do is actually pass in a valid MySQL function in the value of the array inside your Model’s find method. Essentially, what this is saying is that you want Phalcon to group the results by this “your_column_name_here” column. By adding the MIN MySQL function inside this value, Phalcon will apply this function to your group and satisfys MySQL’s only_full_group_by setting that is enabled by default in MySQL 5.7.
Hope this clarified things a bit more for you.
Happy Coding!

