11

我是 cakephp 的初学者,我想IN在 find 方法中使用 SQL 运算符,我有单词表。
我的代码是:

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

,这段代码创建了这个查询:

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

但我需要这个查询

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

怎样才能得到这样的查询(使用 IN 运算符)
谢谢。

4

1 回答 1

28

你需要让 cake 来处理它——简单地使用它,因为它是一个字符串(但要确保它是一个数组):

$arrayOfIds = [1, 5, ...];
$this->Word->find('all', array(
    'conditions' => array('Word.wordid' => $arrayOfIds)
));
于 2012-02-25T15:01:19.040 回答