Hi All,
I am using yii 2 for my rest api application but I am getting stuck in getting data from relational table using joins.
I have two table team and team_player with their corresponding Active record Team and TeamPlayer.
In Team relation is defined as
class Team extends ActiveRecord
{
public function getTeamPlayer(){
return $this->hasMany(TeamPlayer::className(), [‘team_id’=> ‘id’]);
}
}
and in TeamPlayer relation is defined as
class TeamPlayer extends ActiveRecord
{
public function getTeam(){
return $this->hasMany(Team::className(), [‘id’=>‘team_id’]);
}
}
In my rest API controller, I am using following query to get the data .
$player_team = Team::find()
->select([‘team.name’,‘team_player.status’])
->innerJoinWith(‘teamPlayer’, true)
->where([‘team_player.player_id’=> $id])
->all();
By using above statement , I am getting only team.name while not getting team_player.status.
but printing the sql query, running in phpmyadmin, I am getting both name and status.
Please help me to get team_player.status value.