一對多的關係,我創建3個表:許多以先進的搜索
User
User-Group
Group
在哪裏我可以有一個多一對多的關係。
但我如何創建搜索方法找到它? 我怎樣才能獲得具有特定組的所有用戶,像
select u.* from users as u, user-group as ug, group as g
where g.name = "group_1" and ug.group_id = g.id and ug.user_id = u.id ?
到目前爲止我的代碼:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'group'=>array(self::MANY_MANY, 'Group', 'tbl_profile(id_user, id_group)'),
'groupList' => array(self::HAS_MANY, 'Group', 'id_user'),
}
$criteria->with=array('groupList' => array(
'condition' => 'id_user = 1',
));
Upvotes總是感激,謝謝! – acorncom 2012-04-09 13:04:39