カテゴリと製品があり、製品カテゴリメニューを作成するために空でないカテゴリを選択する必要があります。 空でない場合は、カテゴリに製品が含まれているか、または子カテゴリに製品が含まれていることを示します。私はスコープでそれをやりたかったのですが、遠くになっているようには見えません。関連モデルまたは関連モデルを持つ子孫のモデルのみを選択する
何か種類の以下のような、しかし、私は、再帰的なカテゴリ階層下の複数のレベルをチェックする必要が
/**
* 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;
}
...
}
ここで、SQLの質問ですか? –
フレームワークの抽象化の下で、yiiに慣れていない場合はSQLの問題を「見る」ことができません。 – dimvic