Column Disambiguation In Scopes

Hi all,

How can I disambiguate a column in the scopes ?

I’m using this code, the table is called events, of course I can use the table name in scope




class EventsQuery extends ActiveQuery

{

    public function approved()

    {

        $this->andWhere('status= ' . Events::STATUS_APPROVED);

        //$this->andWhere('events.status= ' . Events::STATUS_APPROVED);

        return $this;

    }

} 

but when I need to use scopes in dataproviders I use this code ( I have a relation called event)




$query = EventsDates::find()

            ->future()

            ->joinWith([

                'event' => function ($query) {

                        $query->from(['event' => 'events'])->approved();

                    },

                'event.categories' => function ($query) {

                        $query->from(['categories' => 'categories_events']);

                    }]);


        $dataProvider = new ActiveDataProvider([

            'query' => $query,

            'pagination' => [

                'pageSize' => 21,

            ],

        ]);

so if I use the table name the EventsQuery method when I construct the the query the events table doesn’t exist as it has an alias “event” so the query will not work because events.status doesn’t exist.

Of course I can replace the query in the dataprovider with


$query->from(['event' => 'events'])->andWhere(['status='. Events::STATUS_APPROVED]);

Is this the correct way??