我A
属于B
且B
属于C
。假设C
有一个property
,我想查找所有A
,使其C.property
值为$myVar
。
我想做的是像
A::model()->with('B.C')->findAllByAttributes(array('C.property'=>$myVar))
每当我这样做时,
$brands = FPfdPetItemBrand::model()->with('mImportOperation.mImport')->findAllByAttributes(array('mImport.m_import_id'=>$latestImport->m_import_id));
Yii不高兴:
CDbException
表“f_pfd_pet_item_brand”没有名为的列 “mImport.m_import_id”。
我已经能够通过JOIN
实现我想要的,但有没有更清洁的方法(类似于我试图使用的那种)?
答案 0 :(得分:1)
您无法使用findAllByAttributes()
根据相关属性进行查找。请尝试使用findAll()
$brands = FPfdPetItemBrand::model()->with('mImportOperation.mImport')->findAll('mImport.m_import_id=:import_id',array(':import_id'=>$latestImport->m_import_id));
(我已经测试了上面的内容。但它应该有用)