public function getGames() { return $this->hasMany(Game::className(), ['user_id' => 'id']); }
/** * Defines many-to-many relation with game model via table game_has_player * @return list of games where user has marked his presence */ public function getGames() { return $this->hasMany(Game::className(), ['id' => 'game_id'])->viaTable('game_has_player', ['player_id' => 'id'])->select('*, (SELECT presence FROM game_has_player WHERE player_id=' . $this->id . ' AND game_id=games.id LIMIT 1) as presence'); }
/** * Defines one-to-many relation with games table * @return \yii\db\ActiveQuery */ public function getGames() { return $this->hasMany(Game::className(), ['team_id' => 'id'])->andOnCondition(['>', 'datetime', date('Y-m-d H:m:s')]); }