how using SQL IN operator in find method of cakephp ORM

六眼飞鱼酱① 提交于 2020-01-20 04:02:28

问题


i am beginner in cakephp , and i want use SQL IN operator in find method , i have words table.
my code is :

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

, and this code create this query :

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

but i need this query

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

how can getting like this query (using IN operator )
thanks.


回答1:


you need to let cake take care of that - simply 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)
));


来源:https://stackoverflow.com/questions/9445086/how-using-sql-in-operator-in-find-method-of-cakephp-orm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!