0

我有 2 个模型:与 (User.php) 连接的项目和用户:

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 中与项目连接的所有用户。我该怎么做?

4

2 回答 2

1

我找到了解决方案:

$criteria=new CDbCriteria;

foreach($model->users as $cur) {
    $criteria->addCondition("ID != ".$cur->ID);
    }

$users=User::model()->findAll($criteria);

$dataProvider2=new CActiveDataProvider('User');
$dataProvider2->data = $users;
于 2013-06-19T06:26:34.763 回答
0

尝试这个:

$users = User::model()->with('projects')->findAll(array(
    'together' => true,
    'condition' => 'projects.id IS NULL',
));
于 2013-06-18T21:00:09.920 回答