The question rep on the toaster https://toster.ru/q/207608
So. There is a social network. A bunch of tables and dependencies. Here are some of them. The user can be the owner of the club (club.owner_id) and can be in clubs (users_clubs) - many_many:

Each user generates events. Events are bound to the user only. It is necessary to draw a conclusion in the gridview list of events in the club. That is, display the events of all users belonging to a particular club.
I sketched this sql:
SELECT e.id, ecclub_id, u.name FROM events AS e JOIN user AS u ON e.owner_id = u.id JOIN users_clubs AS uc ON uc.user_id = u.id JOIN clubs AS c ON c.id = uc.club_id WHERE c.id = :club_id There are models:
User :
public function getClubs(){ return $this->hasMany(Club::className(), ['id'=>'club_id']) ->viaTable('users_clubs', ['user_id'=>'id']); } Event :
public function getOwner(){ return $this->hasOne(User::className(), ['id'=>'owner_id']); } Club :
public function getMembers($count = 100){ return $this->hasMany(User::className(), ['id'=>'user_id']) ->limit($count) ->viaTable('users_clubs', ['club_id'=>'id'], function($query){ $query->where(['status'=>User::STATUS_CLUB_JOINED_APPROVED]); }); } Search Event Models :
public function search($params){ $query = Event::find(); // я так понимаю вся движуха должна быть здесь или вынесена в EventQuery впоследствии $this->scenario = 'search'; $dataProvider = new \yii\data\ActiveDataProvider([ 'query'=>$query, ]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); return $dataProvider; } Does anyone have the time and opportunity to help with the question? Thank you.
e.id, ecclub_id, u.name? - Igor