所以,有类别和产品,我需要选择不为空的类别才能构建产品类别菜单。非空表示该类别包含产品或后代类别包含产品。我想用范围来做,但我似乎走不远。
类似于以下内容,但我需要递归检查类别层次结构的更多级别
/**
* This is the model class for table "shopCategories".
*
* The followings are the available columns in table 'shop_categories':
* @property integer $id
* @property integer $parentId
* @property integer $order
* @property integer $isActive
* @property integer $cstamp
* @property integer $mstamp
*
* The followings are the available model relations:
* @property ProductCategory $parent
* @property ProductCategory[] $children
* @property ProductCategoryL10n[] $l10n
* @property ProductCategoriesProducts[] $productsJunction
*/
class ProductCategory extends BogoActiveRecord
{
...
public function nonEmpty()
{
$this->getDbCriteria()->mergeWith(array(
'with' => array(
'children',
'children.products'=>array(
'condition'=>'products.isActive=1',
'joinType'=>'INNER JOIN', 'limit'=>1
),
),
));
return $this;
}
...
}