そのため、カテゴリと製品があり、製品カテゴリメニューを作成するには、空でないカテゴリを選択する必要があります。空でないということは、カテゴリに製品が含まれているか、子孫カテゴリに製品が含まれていることを意味します。スコープでやりたかったのですが、なかなか遠くないようです。
次のようなものですが、カテゴリの階層の下位レベルを再帰的にチェックする必要があります
/**
* 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;
}
...
}