CakePHP syntax for find conditions

19,845

You need to put >= on the correct side of the array:

$this->User->find('list', array(
    'conditions'=>array('User.id >=' => 1)));

as documented in the "official" documentation:

http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions

Share:
19,845
Ajay K
Author by

Ajay K

Updated on June 04, 2022

Comments

  • Ajay K
    Ajay K almost 2 years

    I have a table called Users and the following find works fine:

    $users = $this->User->find('list', array('conditions'=>array('User.id'=>1)));
    

    However, if I try to get a list of users with "User.id != 1" or "User.id >= 5", the find does not return data.

    The syntax I have used is

    $users = $this->User->find('list', array('conditions'=>array('User.id'=>'<> 1')));
    

    AND

    $users = $this->User->find('list', array('conditions'=>array('User.id'=>'>= 1')));
    

    The debug query generated by Cake for the User.id => '<> 1') case is

    SELECT `User`.`id`, `User`.`first_name` FROM `mesh2`.`users` AS `User` WHERE `User`.`id` = '<>1',
    

    which seems to be incorrect.

    I have used the examples from Alvin's site. Any ideas?