【问题标题】:cakephp 3 - Impossible to generate condition with empty listcakephp 3 - 不可能用空列表生成条件
【发布时间】:2019-11-14 20:16:27
【问题描述】:

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

请帮忙

【问题讨论】:

  • 您是说$category_ids 包含这些值,但查询构建器另有说明,我倾向于相信查询构建器,除非您能想出一个重现错误的示例,尽管提供的值。

标签: associations cakephp-3.7


【解决方案1】:

当您通过use ($category_ids) 传递变量时,Cake 会执行查询。因此结果执行不会返回任何东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 2019-07-11
    • 2017-03-09
    相关资源
    最近更新 更多