你如何在新的 CakePHP 中使用 where in 子句?我正在努力:
$restaurants->find()->where(['id' => $r_ids])->all();
我在查询中需要的 id 数组在哪里$r_ids
,但这不能按预期工作。
你如何在新的 CakePHP 中使用 where in 子句?我正在努力:
$restaurants->find()->where(['id' => $r_ids])->all();
我在查询中需要的 id 数组在哪里$r_ids
,但这不能按预期工作。
在 CakePHP 3.x 中,现在需要指明数据类型,对于值数组,它需要[]
附加到类型:
$query = $articles
->find()
->where(['id' => $ids], ['id' => 'integer[]']);
或显式使用IN
关键字:
$query = $articles
->find()
->where(['id IN' => $ids]);
也可以看看
在 CakePHP 3.x 上试试这个
$query = $restaurants
->find()
->where(['id IN' => $r_ids]);
$query->all();
您还可以使用简短的语法:
$result = $restaurants->find('all',
['conditions' => ['id IN' =>$r_ids]]
)->all();
在 Cakephp 3.x 中,如果您有多个 where 条件,那么您的查询将如下所示:
return $this
->find()
->contain([
'XYZ.Articles',
'YYY.Managers',
'ZZZ.Readers',
])
->where([
'ID' => $ids,
'READER.STATUS' => $xyz,
],[
'ID' => 'integer[]'
])
;