1

I have a problem with my Cakephp(2.6) find-query and deep association.

My Relations:

Item hasMany Variant
Variant hasAndBelongsToMany Color

I am trying to find all Items that have at least one variant with the color = blue.

$options['contain'] = array(
     'Variant' =>array(
         'Color' => array( 
            'conditions' => array(
                'Color.name =' => 'blue'
))));

$this->Item->find('all',$options);

The above query returns items having no variant.

How do I tell Cake to only return those Items having Variants that have at least the color blue?

Oops D'oh
  • 941
  • 1
  • 15
  • 34
3und80
  • 364
  • 6
  • 20

1 Answers1

0

You cannot do it like this, you must find variants having the color you want. Try this

$this->Variant->Color->find(
    'all',
    array(
        'conditions' => array('Color.name' => $color),
        'contain' => array(
            'Variant' => array(
                'Item',
            )
        )
    )
);
kaklon
  • 2,422
  • 2
  • 26
  • 39