You probably want a little, slightly obscure, gem called joins.
In use it looks something like:
$this->find('all', array(
'conditions' => $conditions,
'joins' => array(
array(
'table' => 'model2',
'alias' => 'Model2',
'type' => 'inner',
'foreignKey' => model1_id,
'conditions'=> array(
'Model2.another_fk = Model1.id'
)
)
)
));
Check out Nate's nice article on the subject: (he talks about habtm
but it is just as useful for hasMany)
http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find
/Martin
On Mar 11, 2:39 pm, Svel <[email protected]> wrote:
> Searching for 2 days and found nothing =(
>
> How i can build this SQL code:
> SELECT `m1`.`id`, COUNT(`m2`.`id`) as cnt
> FROM `m1` LEFT JOIN `m2` ON (`m1`.`id` = `m2`.`m1_id`) WHERE 1=1
> GROUP BY `m2`.`m1_id`
> ORDER BY `m1`.`id`
>
> is it real without custom Model->query() ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---