This blog is about the PHP solutions I have to think of when I'm developing systems almost every single day...

Monday, June 30, 2008

Using functions in cakephp queries

Sometimes you need to use functions in your queries for example using datediff. How would you do it in cakephp? Simply don't assign any value to the key and it will be inserted as it is. For example to get the query "where datediff(deadline,now())<7" you'd do

$this->Decision->find(array('datediff(deadline,now())<7'));

Simple, efficent, nice.

The guts of a query

Sometimes to create more complex queries in cakephp you'd have to refer directly to the source code. If you want to know how do they change all of that array into the where clause of your query just search the api for conditionKeysToString.

About Me

My Photo
Abdullah Zainul Abidin
I am what I am because of what I am...
View my complete profile