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

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

问题描述

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

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)

如何获得这样的查询(使用 IN 运算符)
谢谢.

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

推荐答案

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

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

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

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