class Category extends CActiveRecord
{
...
public function relations()
{
return array(
'parent' => array(self::BELONGS_TO, 'Category', 'parent_id'),
'children' => array(self::HAS_MANY, 'Category', 'parent_id'),
'products' => array(self::MANY_MANY, 'Product', 'shop_categories_products(category_id, product_id)'),
);
}
...
//scope wannabe
public function notEmpty()
{
$this->getDbCriteria()->mergeWith(array(
'with' => array('children', 'children.products'),
// 'condition' => 'children.id is not null OR children.products.id is not null',
));
return $this;
}
}
with the scope "notEmpty" i want to filter categories that contain products or child categories with products
of course my "children.products.id is not null" condition is not working
i tried to define the ‘children.products’ with as ‘children.products’=>array(‘joinType’=>‘right join’), doesn’t work
any ideas?