User Inner Join From An Inner Table

Hi.

What i wanna do is something like

select * from Category inner join Item on Category.id = Item.id_category inner join Images on Item.id = Images.id_item.

I have a scope on the item to get only items with images an a scope in the category to get only the categories with items.

But how can i get only categories with itens that have images.

Is there a way to modify this




public function scopes() {

      return array(

          'withItem'=>array(

              'with'=>'item',

              'condition'=>'item.id is not null',

          ),

      );

  }



My Category relation




public function relations()

{

	// NOTE: you may need to adjust the relation name and the related

	// class name for the relations automatically generated below.

	return array(

	  'item'=>array(self::HAS_MANY, 'Item', 'id_category')

	);

}



How can i do that?

I tried to put and item.image.id is not null but no lick

Just use the with() method and force using two relations with an inner join:




$categories = Category::model()->with(array(

    'items' => array('joinType'=>'INNER JOIN', 'together'=>true),

    'items.images' => array('joinType'=>'INNER JOIN', 'together'=>true),

)->findAll();



Notice that you should name your relations correctly, if it’s a collection it should be in plurar form.