I am trying to join two tables between Deliveries and Employees. The two keys that join the tables are the EMPLOYEEID on the employees table and the DRIVERID on the Deliveries table. I have reason to believe that my associations are correct in the table classes but no matter what I change I end up getting the default Employees.id as the binding key and not Employees.EMPLOYEEID. What am I doing wrong?
SELECT Deliveries.DELIVERYID AS `Deliveries__DELIVERYID`, Deliveries.DSTATUS AS `Deliveries__DSTATUS` FROM deliveries Deliveries LEFT JOIN employees Employees ON **Employees.id = (Deliveries.DRIVERID)',**
I have the following
class DeliveriesTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Auditable');
$this->belongsTo('Clients')->setForeignKey('client_id');
$this->belongsTo('Employees')->setForeignKey('DRIVERID');
}
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
{
$date = new \DateTime($data['ORDERDATE']);
$time = new \DateTime($data['ORDERTIME']);
$data['ORDERDATE'] = $date->setTime($time->format('H'), $time->format('i'), $time->format('s'));
}
}
class EmployeesTable extends Table
{
public function initialize(array $config)
{
$this->hasOne('Deliveries')->setbindingKey('EMPLOYEEID');
}
}