New syntax for conditions

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 ;-)


  1. lemp
    Posted February 20, 2006 at 4:45 pm | Permalink

    What about != ?

  2. Posted February 20, 2006 at 4:59 pm | Permalink

    That is not an sql operator ;-) Use <>

One Trackback/Pingback

  1. […] Yesterday, I wrote already about the new syntax for conditions. Well, most of it is outdated today ;-) The examples I showed do no longer work, they cause an “sql syntax” error: […]

%d bloggers like this: