I'm developing a Plugin with ModelA hasMany ModelB. I can save correctly all data with a simply saveAll across the two models.
But when I try to execute a simple query across the two models something strange happens.
This query work:
$ModelA = new ModelA();
$result = $ModelA->find('all', array(
'recursive' => 1
));
pr($result);
Array
(
[0] => Array
(
[ModelA] => Array
(
[id] => 1
[field] => value
)
[ModelB] => Array
(
[0] => Array
(
[id] => 1
[model_a_id] => 1
)
[1] => Array
(
[id] => 2
[model_a_id] => 1
)
)
)
)
But adding a condition on ModelB don't work:
$ModelA = new ModelA();
$result = $ModelA->find('all', array(
'recursive' => 1,
'conditions' => array(
'ModelB.id' => 2
)
));
pr($result);
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ModelB.id' in 'where clause'
But this work:
$ModelA = new ModelA();
$result = $ModelA->ModelB->find('all', array(
'recursive' => 1,
'conditions' => array(
'ModelA.field' => 'value'
)
));
pr($result);
Array
(
[0] => Array
(
[ModelB] => Array
(
[id] => 2
[model_a_id] => 1
)
[ModelA] => Array
(
[id] => 1
[field] => value
)
)
)
Someone have an idea? Thanks!