wdoxlrx 2012-07-10 11:09:34 2794次浏览 1条回复 0 0 0

我有三个表:table_aa, table_bb,table_cc table_aa: id 1 2
table_bb: id table_aa_id 1 1 2 1 3 2 4 2 5 2 table_cc: id table_bb_id 1 2 2 5

table_aa的model文件里面有relation:

'bb' => array(self::HAS_MANY, 'Table_bb', 'table_aa_id'),

table_bb的model文件里面有relation:

'table_cc' => array(self::HAS_ONE, 'Table_cc', 'table_bb_id'),

现在我想找出当table_aa=1的时候,table_cc的记录 我知道sql语句select * from table_cc where table_bb_id in(select id from table_bb where table_aa_id = 1);可以找出我想要的结果。我现在想用Yii根据关系查找出想要的结果,请问我应该怎么写?

  • 回复于 2012-07-11 11:27 举报

    condition => "exists (select * from table_bb where table_aa_id=1 and table_bb.id=table_cc.table_bb_id)"

您需要登录后才可以回复。登录 | 立即注册