[英]Yii2 many to many doesn't return all relations
I have a many to many relationship of users to private leagues with a connecting table of league_user
. 我有很多用户与私人联盟的关系,并有一个联盟表的league_user
。 However, when I use $user->privateLeagues
it only returns the first relationship. 但是,当我使用$user->privateLeagues
,它只返回第一个关系。
Here are my relationship definitions: 这是我的关系定义:
public function getLeagueUsers()
{
return $this->hasMany(LeagueUser::className(), ['user_id' => 'id']);
}
public function getPrivateLeagues()
{
return $this->hasMany(PrivateLeague::className(), ['id' => 'league_id'])
->via('leagueUsers');
}
Example table data: 示例表数据:
league_user league_user
user_id league_id
1 1
1 2
private_leagues private_leagues
id name
1 first
2 second
升级我的Yii版本解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.