I have these relations:
Attendance belongs to Employee
Schedule belongs to Employee
This find() works just fine to get all Attendance records in a date range.
$data = $this->Attendance->find('all', array(
'contain' => array(
'Employee' => array(
'Schedule' => array(
'conditions' => array('sche_status' => 1),
'order' => 'sche_valid DESC',
'limit' => 1
))
),
'conditions' => $conditions,
'order' => array('employee_id', 'att_date')
)
);
However, this Schedule condition
'conditions' => array('sche_status' => 1),
gets the "current" Schedule. Problem is when Employee has more than one Schedule in the date range. In order to get the relevant Schedule for it's parent Attendance record, I need to also condition on Attendance.att_date
Tried
'conditions' => array('sche_status' => 1, 'ho_valid <=' => Attendance.att_date)
and
'conditions' => array('sche_status' => 1, 'ho_valid <=' => $this->Attendance.att_date)
How can I reference Attendance.att_date from the contan Schedule conditions? Is that possible? My current datasets are pretty clean and my find() is dry, wouldn't want to make a mess here.
Any help greatly appreciated.