I’ve been trying to figure this one out forever, I want to check in scopes if a model is currently staffed at an event, and the table is a many_many table with model_id and event_id as foreign keys.
I apologize if this is a noob question, I’m a designer turned developer, and just love Yii’s fairly simple learning curve, and power, but now i’ve seemed to hit several walls in my app.
Im trying something like this at the moment:
In controller:
$avail_models = Person::model()->with('picture')->active()->notStaffed()->people(2)->findAll();
In model:
public function scopes(){
return array(
'people'=>array(
'order' => 'first_name DESC'
),
'active'=>array(
'condition'=>'t.status_id ='.Status::STATUS_ACTIVE
),
'has_image'=>array(
'condition'=>'profile_image_id <> NULL'
),
'notStaffed'=>array(
'order' => 'first_name DESC'
)
);
}
public function people($cat=2){
$this->getDbCriteria()->mergeWith(array(
'condition'=>'category_id ='.$cat,
));
return $this;
}
public function notStaffed($event_id){
$this->getDbCriteria()->mergeWith(array(
'condition'=>'tbl_models_events.model_id != :mid AND tbl_models_events.event_id !=:eid',
'params'=>array(':mid'=>$this->id, ':eid'=>$event_id),
));
return $this;
}
I get an error saying my db has unknown column…?