New syntax for conditions II

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:

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

To make them work again, we have to add a space to the values:

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

There are also some new features. By default, all conditions are concatenated with “AND”. If you want to use an “OR”, you have to do it in the following way:

$this->User->findAll(array('User.firstname' => ' = Daniel', 
                                               ' OR User.firstname' => ' = Hugo'));

It is now also possible to use “–return” for a value, i.e. your value will not be quoted by CakePHP. Example:

$this->User->findAll(array('User.firstname' => "--return = 'Daniel'"));

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


  1. Posted February 21, 2006 at 9:27 pm | Permalink

    is there a rational for requiring the space by the developer? It seems to me that the system ought to be smart enough to check that and insert the space if it is lacking, thus saving the developer YA obscure syntactic error.

  2. Posted February 21, 2006 at 9:33 pm | Permalink

    I should mention that the space notwithstanding, I really like this new syntax. Good stuff.

  3. Posted February 21, 2006 at 10:28 pm | Permalink


    The reason the space is need is not that I can not add it if it is missing, it acts more like a terminator so I do not have to write a regex for every possible condition operator. This could be changing soon, most of the code I have added will be refactored before rolling into the releases.

    Doing it more of a POC

One Trackback/Pingback

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

Post a Comment

Required fields are marked *

%d bloggers like this: