Answer the question
In order to leave comments, you need to log in
Yii2: How to make hasMany through cross table and count all records?
I do not quite understand how to make a selection through the crosstab.
There is a list of clubs. there are users who can be in several clubs at once.
You need to
1. count the number of users in each club
2. display a list of users on the club page
Answer the question
In order to leave comments, you need to log in
public function getMembers(){
return $this->hasMany(\app\models\User::className(), ['id'=>'user_id'])
->viaTable('users_clubs', ['club_id'=>'id']);
}
public function getMembersCount(){
return $this->getMembers()->count();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question