2013-06-18 42 views
0

我有2種型號:項目,並與(user.php的)連接的用戶:Yii的CActiveDataProvider MANY :: MANY

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(
      "projects"=>array(self::MANY_MANY, 'Project','projects_users(user_id, project_id)'), 
    ); 
} 

我想表明在CActiveDataProvider誰是與項目有關的所有用戶。我該怎麼做?

+0

有很多的在網上的例子如何做到這一點。看看這裏例如:http://www.yiiframework.com/forum/index.php/topic/12637-please-explain-how-to-do-many-to-many-relationships-for-newcomer/ –

+0

我無法找到任何解決方案 – rafal235

回答

1

我找到了解決辦法:

​​
+0

哦,我的上帝,這很容易!非常感謝! – KryDos

0

試試這個:

$users = User::model()->with('projects')->findAll(array(
    'together' => true, 
    'condition' => 'projects.id IS NULL', 
));