如何使用SQL IN运算符在cakephp ORM的find方法 [英] how using SQL IN operator in find method of cakephp ORM

查看:126
本文介绍了如何使用SQL IN运算符在cakephp ORM的find方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我的代码是: / p>

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

,此代码创建此查询:

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)

如何获得这样的查询b $ b感谢。

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

推荐答案

你需要让蛋糕去处理 - 只是使用它,因为它是一个字符串请确保它是一个数组):

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

这篇关于如何使用SQL IN运算符在cakephp ORM的find方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆