以下是我的数据库结构:
以下是我的TimeSlot.php的片段:
public $hasMany = array(
'Response' => array(
'className' => 'Response',
'foreignKey' => 'time_slot_id`'
)
);
和Response.php:
public $belongsTo = array(
'TimeSlot' => array(
'className' => 'TimeSlot',
'foreignKey' => 'time_slot_id'
)
);
当我将此行添加到Meetings Controller中的操作时
$this->loadModel("TimeSlot");
$time_slot = $this->TimeSlot->find("first");
debug($time_slot);
结果为:
Database Error
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`.`responses` AS `Response` WHERE `Response`.`time_slot_id` = (1)' at line 1
SQL Query: SELECT `Response`.`id`, `Response`.`invitee_id`, `Response`.`time_slot_id`, `Response`.`time_slot_id`` FROM `meetingscheduler`.`responses` AS `Response` WHERE `Response`.`time_slot_id` = (1)
我对我的代码有什么不妥之处。但我认为它与TimeSlot和Response Models之间存在关系,因为一旦我忽略了关系,它的工作正常。
答案 0 :(得分:3)
这里有一个额外的刻度:
.`time_slot_id``
^^^