0

该模型与Team有两个多方关系Game

public function getGamesWhereTeamIsSetAsHome()
{
    return $this->hasMany(Game::className(), ['teamHome' => 'id']);
}

public function getGamesWhereTeamIsSetAsAway()
{
    return $this->hasMany(Game::className(), ['teamAway' => 'id']);
}

我想要一个返回所有游戏的has-many 关系,这些游戏将 teamHome 或 teamAway 设置为 team 的 id(就像上面两个关系的组合)。

public function getGames()
{
    return /* code here */;
 }

我如何建立这样的关系?

4

1 回答 1

0
public function getGames($id)
{
   return Games::find()->where(['or',['teamHome'=>$id],['teamAway'=>$id]])->all();
}

并在打电话时

$games = $model->getGames($model->id);
于 2016-05-18T10:49:15.883 回答