Using Dardo's intuitive example:

$this->Product->bindModel(array(
  'belongsTo' => array(
    'ParentCategory' => array(
      'className' => 'Category',
      'foreignKey' => false,
      'conditions' => 'ParentCategory.id=Subcategory.category_id',
      'fields' => array()
    )
  )
));
$results = $this->Parent->find('all', array(
  'conditions' => array(
    'ParentCategory.name' => 'fred'
  )
));

On Jun 10, 4:18 am, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
> Having:
>
> A = Product, B = Subcategory, C = Category, then
>
> Product belongsTo Subcategory, Subcategory belongsTo Category = A
> belongsTo B, B belongsTo C
>
> Find all Products (A) where Category.name = fred (C)
>
> // using containable
>
>                 $conditions = array('Category.name' => 'fred');
>                 $contain = array('Subcategory', 'Subcategory.Product');
>                 $categories = $this->Category->find('all', 
> compact('conditions', 'contain'));
>
> However it will not do a join, if a join is what you want you can
> always make a raw query.
>
> Regards,
> - Dardo.
>
> 2008/6/9 Alex Seim <[EMAIL PROTECTED]>:
>
>
>
> > Have you found a clear answer about this?
>
> > On 18 Απρ, 04:08, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >> I have 3 models:
> >> A belongs to B
> >> B belongs to C
>
> >> I want tofindAllA where C.name='fred'.
>
> >> I had assumed that cake would justleft jointhe 3 tables and c.name
> >> would be accessible in the query. But regardless of what level of
> >> recursive I set, it only left joins A and B and then does
> >> multitudinous other queries to get C. Hence I can't refer to c.name in
> >> the query.
>
> >> I've searched and read lots of messages and trac item that implies
> >> that Cake is doing what it thinks is correct.
>
> >> If so, what is the recommended way of doing this query?
>
> >> Do the new 'bindable'/'container' behaviours (which should be used?)
> >> help with this?
>
> >> Thanks
> >> Peter
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to