我有一个组织者,他们组织玩家可以参加的比赛。
所以我有桌子组织者、锦标赛、参与、玩家。
我在组织者模型中建立了一个关系,该模型为我提供了所有在该组织者组织的锦标赛中付费的玩家。
public function getTournaments()
{
return $this->hasMany(Tournament::className(), ['organizer' => 'id'])->where(['hasBeenAudited' => 1]);
}
public function getParticipations()
{
return $this->hasMany(Participation::className(), ['tournament' => 'id'])
->via('tournament')->where(['didShowUp' => 1]);
}
public function getPlayers() {
return $this->hasMany(Player::className(), ['id' => 'player'])
->via('participation');
}
所以现在我可以$model->players
检索所有曾为该组织效力过的球员。
我现在想$model->players
根据玩家为该组织参加的锦标赛数量排序,以便为该组织参加最多锦标赛的玩家将出现在顶部。
我怎么做?