I cant get data from 2 tables with conditions on each. There is no example in the docs. I just need rows from students table where a field is flagged as inactive and corresponding rows from Guardian table the email field is not null. Guardian has many Students. I get results but I get null values for Guardian email. I have tried many combinations with ID, model name etc but I am just not getting it.
$guardianFound = $this->Student->find('all', array(
'contain' => array( 'Guardian', array(
'conditions' => array('guardian_email !=' => null),
'fields' => array('id,guardian_email','guardian_first_name,guardian_last_name')
)),
'conditions' => array('student_inactive' => 1),
'fields'=> array('student_inactive' ),
'recursive'=> -1
));
Result:
(int) 0 => array(
'Student' => array(
'student_inactive' => true
),
'Guardian' => array(
'guardian_email' => '',
'guardian_first_name' => 'Tulay',
'guardian_last_name' => 'Karadavut',
'id' => '100'
)
)
http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html