cakephp 3-无法使用空列表生成条件

时间:2019-07-04 06:41:14

标签: associations cakephp-3.7

在cakephp 3查询中,如果在包含查询中添加了“ IN”条件,则会出错。

$itemsquery = $Students->find('all');
$itemsquery->select(['Students.id']);

$itemsquery->matching('CategoriesStudents');
$itemsquery->contain([
'CategoriesStudents' => function ($q) use ($category_ids) {
return $q->where(['CategoriesStudents.category_id IN' => $category_ids]);
}
]);

// debug($itemsquery);
$items = $itemsquery->toArray(); 

错误

Impossible to generate condition with empty list of values for field (`CategoriesStudents`.`category_id`)

Error: An Internal Error Has Occurred.
An Internal Server Error Occurred

表是

  1. categories_students

category_id,student_id

  1. 学生

  2. 类别

$ category_ids数组

Array
(
    [1] => 57
    [2] => 60
    [3] => 58
    [4] => 13
    [5] => 78
    [6] => 56
    [7] => 59
    [8] => 79
    [9] => 95
    [10] => 94
    [11] => 96
    [12] => 93
    [13] => 82
    [14] => 23
    [15] => 82
    [16] => 14
    [17] => 16
    [18] => 101
    [19] => 14
)

请帮助

0 个答案:

没有答案