New syntax for conditions

Published on and tagged with cakephp  feature  programming  sql

RC5 is still warm, but the development goes on ;-) And so a new syntax has been added for conditions. With “–return” you can avoid that your condition is quoted. Example:

$this->User->findAll('--return User.company_id = 1');

That generates something like

... WHERE User.company_id = 1 ...

That feature is useful if you have complex conditions you cannot express in another way with CakePHP. But be careful using it if your application should work with different databases.

The more important change is the way you can specify the conditions. Some examples:

$this->User->findAll(array('User.firstname' => '= Daniel'));
$this->User->findAll(array('User.firstname' => 'LIKE %an%'));
$this->User->findAll(array('User.age' => '> 18'));

That also works for the following operators: <>, >=, <=, and <.

Update (2006-02-21): The examples about specifying the conditions are no longer valid, see New syntax for conditions II.

Update (2006-02-22): All examples in this post are no longer valid!

Update (2006-02-28): The last three examples are valid again in RC6 ;-)

3 comments baked

Bake a comment

(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License