如何在 CakePHP 查询中创建`IN` 子句? [英] How to create a `IN` clause in CakePHP query?
本文介绍了如何在 CakePHP 查询中创建`IN` 子句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在新的 CakePHP 中使用 where in 子句?我正在尝试:
How do you make it where in clause in new CakePHP? I'm trying:
$restaurants->find()->where(['id' => $r_ids])->all();
其中 $r_ids
是我在查询中需要的 id 数组,但这不能按预期工作.
Where $r_ids
is array of ids I need in my query, but this doesn't work as expected.
推荐答案
在 CakePHP 3.x 中,现在需要指明数据类型,对于值数组需要有 []
附加到类型:
With CakePHP 3.x it's now necessary to either indicate the data type, which for an array of values need to have []
appended to the type:
$query = $articles
->find()
->where(['id' => $ids], ['id' => 'integer[]']);
或明确使用 IN
关键字:
or to explicitly make use of the IN
keyword:
$query = $articles
->find()
->where(['id IN' => $ids]);
另见
这篇关于如何在 CakePHP 查询中创建`IN` 子句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文