I’m trying to filter my search results based on the role of a user. I have a table which is related to the user on two occasions. 1 when the user is the app owner. 2 whent the user is in the user_has_app table:
class App extends AsoActiveRecord {
/**
* @return string the associated database table name
*/
public function tableName() {
return 'app';
}
/**
* @return array relational rules.
*/
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(
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
'appVersions' => array(self::HAS_MANY, 'AppVersion', 'app_id'),
'users' => array(self::MANY_MANY, 'User', 'user_has_app(app_id, user_id)'),
);
}
public function search($size = 18) {
$criteria = new CDbCriteria();
$criteria->compare('app_name', $this->app_name);
$criteria->with = array('user','users');
$criteria->compare('user.id', Yii::app()->user->getId());
$criteria->compare('user_has_app.app_id', $this->id);
$criteria->compare('user_has_app.user_id', Yii::app()->user->getId());
$criteria->together = true;
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'sort' => array(
'defaultOrder' => 'app_name DESC',
),
'pagination' => array(
'pageSize' => $size,
)
));
}
}
I get the following error