| MySQL and the "HAVING" expression, how do you do it in CakePHP? |
|
|
|
| CakePHP - Basics | |
| Written by Stuart Duncan | |
| Saturday, 30 January 2010 18:46 | |
|
Lately I've been needing to create queries using the "HAVING" expression so that I could find pictures that have received 5 or more votes towards their rating... there are various ways to do that but I really needed to have it use the "HAVING" expression, so I hit the information super highway in search of CakePHP articles and not surprisingly, there were not very many off ramps. I have a working solution now but it's sort of a hack/fix since CakePHP apparently feels that it's not an expression worth including into their vast number of array options. Here's how I did it: The "HAVING" expression is unique in that it needs to be placed directly after the GROUP BY expression, rather than mixed in with the WHERE stuff.... so, the logical solution is simply this:
As I said, it's a bit of a hack/fix in that you're tagging it in with another expression but you know what? It works. Hopefully CakePHP will adress this in the future but until then, feel free to use this. |




