0
以下是協會cakephp3-未知列在哪裏條款
每個學校都有很多學生。 每所學校屬於一個區
$this->table('school');
$this->belongsTo('Districts', [
'foreignKey' => 'district_id'
]);
$this->hasMany('Students', [
'foreignKey' => 'school_id'
]);
比方說,有4個區。 (Districts.id = 1,2,3,4) 在School's Model中,我試圖獲取所有學生的列表。 但是,如果地區是1或2,我只想顯示那些得分超過50分的學生。 而對於其他地區,我試圖給那些得分低於35分的學生展示。 這是我爲上述提到的查找函數。
public function findStudentsList(Query $query, array $options)
{
$query->select(['id','name','modified','created'])
->contain([
'Districts'=> function ($query) {
return $query->select(['id','name']);
},
'Students' => function ($query) {
return $query->where([
'CASE
WHEN Districts.id=1 THEN Students.marks >50
WHEN Districts.id=2 THEN Students.marks >50
ELSE Students.marks < 35
END']);
}
]);
}
但是,當我執行這個,我得到以下錯誤。
Column not found: Unknown column 'Districts.id' in where clause
這是正確的方法嗎?我是CakePHP3的新手。