Sorry but I don’t know how to explain my problem.
I’ve a model Clan with many ClanAdmin
this is the relations:
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(
'naz' => array(self::BELONGS_TO, 'Nazione', 'nazione_id'),
'admins' => array(self::HAS_MANY, 'ClanAdmin', 'clan_id'),
);
}
and in the admin I want to take only the list of clans that can be managed by the current user.
ClanAdmin is composed by id, clan_id and user_id
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
if ( !User::checkRole(User::ROLE_ADMIN) ) {
$criteria->with='admins';
$criteria->condition='admins.user_id=:userID';
$criteria->params=array(':userID'=> User::getUserID());
}
$criteria->compare('nome',$this->nome,true);
$criteria->compare('tag',$this->tag,true);
$criteria->compare('status',$this->status);
return new CActiveDataProvider('Clan', array(
'criteria'=>$criteria,
));
}
This is the error: CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘admins.user_id’ in ‘where clause’
How can I do it? Thank you very much