我在存在的字段上收到此錯誤。我不能顯示TutoringTypes表中的任何字段。我的聯繫是錯誤的,我不知道我犯了什麼錯誤,因爲我相信我遵循了這些慣例。然而,文檔談論複數表名稱,但給單一變量名稱作爲例子?沒有找到我無法在cakephp3中使用下劃線顯示錶中的字段
柱:1054未知列 'tutoring_types.value' 在 '字段列表'
$query3 = $this->Lessons->find()
->contain(['Tutors', 'TutoringTypes'])
->select(['lessons.id','lessons.lesson_date','tutors.id','tutors.first_name','tutors.last_name','lessons.tutoring_type_id',
'tutoring_types.value'])
->where(['Lessons.lesson_date >' => $a3,'Lessons.lesson_date <' => $a4,
'OR' => [['lessons.tutoring_type_id' => 2], ['lessons.tutoring_type_id' => 1]]
]);
Lessons Model
public function initialize(array $config)
{
parent::initialize($config);
$this->belongsTo('TutoringTypes', [
foreignKey' => 'tutoring_type_id'
]);
//////
SELECT
lessons.id AS `lessons__id`,
lessons.lesson_date AS `lessons__lesson_date`,
tutors.id AS `tutors__id`,
tutors.first_name AS `tutors__first_name`,
tutors.last_name AS `tutors__last_name`,
lessons.tutoring_type_id AS `lessons__tutoring_type_id`,
tutoring_types.value AS `tutoring_types__value`
FROM
lessons Lessons
LEFT JOIN tutors Tutors ON Tutors.id = (Lessons.tutor_id)
LEFT JOIN tutoring_types TutoringTypes ON TutoringTypes.id = (Lessons.tutoring_type_id)
WHERE
(
Lessons.lesson_date > '2015-05-30'
AND Lessons.lesson_date < '2016-06-01'
AND (
lessons.tutoring_type_id = '2'
OR lessons.tutoring_type_id = '1'
)
)
http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html http://book.cakephp.org/3.0/en/intro/conventions.html
你是對的,我對於區分大小寫的類型感到困惑。我認爲文檔可以使這個更清晰,因爲在查詢中使用帶小寫字母名稱的模型不應該起作用。不管怎樣,謝謝。 – ajt