Reputation: 2157
How can I write into CakePHP 2.5.2 a left join:
SELECT A.*, B.*, C.*
FROM A
JOIN B on A.id = B.a_id
JOIN c ON (c.b_id = b.id AND c.a_id = a.id)
How can this be written AND c.a_id=a.id
using the find model method into the contain array?
Upvotes: 1
Views: 149
Reputation: 4469
This should work:
$options['joins'] = array(
array('table' => 'table_b',
'alias' => 'B',
'type' => 'LEFT',
'conditions' => array(
'A.id = B.a_id',
)
),
array('table' => 'table_c',
'alias' => 'C',
'type' => 'LEFT',
'conditions' => array(
"C.b_id = B.id",
"C.a_id = A.id"
)
)
);
$ItemA->find('all', $options);
For further reference see:
Upvotes: 1