Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
965 views
in Technique[技术] by (71.8m points)

how using SQL IN operator in find method of cakephp ORM

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)
));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...