I have three models in a cakephp application: ModelX, ModelY and ModelZ. The table for ModelX has the fields parent_id, lft and rght. The associations between the models are as follows:
ModelX hasOne ModelY
ModelY belongsTo ModelX
ModelY hasMany ModelZ
ModelZ belongsTo ModelY
I have a query on ModelX with joins to ModelY and ModelZ like this:
$this->ModelX->find('all', array(
'joins' => array(
array(
'table' => 'modelys',
'alias' => 'ModelY1',
'type' => 'left',
'conditions' => array(
'ModelX.id = ModelY1.modelx_id',
)
),
array(
'table' => 'modelzs',
'alias' => 'ModelZ1',
'type' => 'left',
'conditions' => array(
'ModelY1.id = ModelZ1.modely_id'
)
)
)
));
In the result of this query, I have the data for ModelX, ModelY but NOT ModelZ, I don't know why!!. Can anybody see what is wrong with this query please?