decodingpanda
decodingpanda

Reputation: 594

SQL Syntax validation

Here is my database structure:

enter image description here

Here is the snippet of my TimeSlot.php:

    public $hasMany = array(
    'Response' => array(
        'className' => 'Response',
        'foreignKey' => 'time_slot_id`'
    )
);

and Response.php:

   public $belongsTo = array(
    'TimeSlot' => array(
        'className' => 'TimeSlot',
        'foreignKey' => 'time_slot_id'
    )
);

When I add this line to my action in Meetings Controller:

  $this->loadModel("TimeSlot");
  $time_slot = $this->TimeSlot->find("first");
  debug($time_slot);

This results to:

   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)

I'm a little confused whats wrong with my codes. But I think its the relations ship between TimeSlot and Response Models because once I ignore the ralationships, its working fine.

Upvotes: 0

Views: 114

Answers (1)

Jens
Jens

Reputation: 69470

You have an extra tick here:

.`time_slot_id``
             ^^^

Upvotes: 3

Related Questions