如何使用 Yii.ActiveRecord 查找不相关的记录? [英] How can i use Yii.ActiveRecord to find unrelated records?
本文介绍了如何使用 Yii.ActiveRecord 查找不相关的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个关系模型:
class Model1 extends CActiveRecord
public function relations()
{
return array(
'relation' => array(self::HAS_MANY, 'Model2', 'id_model1'),
)
}
我希望通过 CListView 查看来自模型 1 的那些记录,这些记录与模型 2 无关.显然,我可以使用类似
I want view by CListView those records from Model 1, which unrelated with Model2. Obvious, I can use something like
$criteria->condition = 'id NOT IN (SELECT DISTINCT id_model1 FROM model2_tbl)'
然后将此 $criteria 发送到 ActiveDataProvider.但我在寻找更聪明、更yii-way"的解决方案.存在吗?
and then send this $criteria to ActiveDataProvider. But I look for something more smart, more "yii-way" for solution. Is it exist?
推荐答案
关系查询选项 'joinType' = 'RIGHT OUTER'
和 'condition'=>'left_table.join_field IS NULL'
可能做把戏.
Relational query options 'joinType' = 'RIGHT OUTER'
and 'condition'=>'left_table.join_field IS NULL'
might do the trick.
这篇关于如何使用 Yii.ActiveRecord 查找不相关的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文