How to use SQL IN statement in cakephp ORM search method

I am new to cakephp and I want to use the SQL IN statement in the find method, I have a word table.
my code is:

 $this->Word->find('Word.wordid in (83,82)'); 

and this code will create this request:

 SELECT `Userword`.`userwordid`, `Userword`.`userid`, `Userword`.`wordid`, `Userword`.`date`, `Userword`.`levelid` FROM `userwords` AS `Userword` WHERE `Userword`.`wordid` = (82) 

but i need this request

 SELECT `Userword`.`userwordid`, `Userword`.`userid`, `Userword`.`wordid`, Userword`.`date`, `Userword`.`levelid` FROM `userwords` AS `Userword` WHERE `Userword`.`wordid` IN (83,82) 

how to get such a request (using the IN operator)
thanks.

+8
find orm cakephp in-operator
source share
1 answer

you should let cake take care of this - just use it as it was a string (but make sure it is an array):

 $arrayOfIds = [1, 5, ...]; $this->Word->find('all', array( 'conditions' => array('Word.wordid' => $arrayOfIds) )); 
+22
source share

All Articles