Newbie question again:

I have a table with various types (models, employees etc) and want to use custom scopes to output

i’m doing this right now but doesnt work, what am i doing wrong?

in event controller

$avail_models = Person::model()->with('picture')->people(Person::CATEGORY_MODEL)->findAll();

in person model

 public function people($cat=2) {


            'condition' => 'category_id =' . $cat,


        return $this;


public function scopes() {

        return array(

          'people' => array(

              'order' => 'first_name DESC'




You don’t need to define scopes in two places. In your case a method is enough.

ok, but it doesnt return anything unfortunately when i use it in the controller… :frowning:

Thank you for the fast response, I’m still dealing with these custom scopes, i got the model one to work, but now i have a many_many scope that I can’t get the hang of…

In event controller trying to access the "not_staffed" scope…

public function actionView($id) {

        $event = Event::model()->with('models','confirmed', 'proposed')->not_staffed($id)->findByPk((int) $id);

        $event->address = Address::model()->findByPk($event->address_id);

        $this->render('view', array(

            'event' => $event,



Scope in model referencing table that combines the 2 models.

public function not_staffed($event_id) {


            'alias' => 'notstaffed',

            'condition' => 'tbl_models_events.event_id != :eid',

            'params' => array(':eid' => $event_id),


        return $this;


[b]Error: CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘tbl_models_events.event_id’ in ‘where clause’