У меня есть три таблицы:
user
game
user_game
game.user_id
- пользователь, который СОЗДАЕТ игру. Таблица user_game
описывает пользователей, которые ADDED игры не создают, в ней есть поля user_id
и game_id
. У меня есть GameSearch Model, которая должна искать игры текущего пользователя ДОБАВЛЕННЫЕ. Здесь метод поиска;
public function search($params)
{
// HERE I SHOULD GET ONLY GAMES WHICH ADDED BY USER via table user_game
$query = Game::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'sorting' => SORT_DESC,
]
],
]);
if (!empty($params['pageSize'])) {
$dataProvider->pagination->pageSize = $params['pageSize'];
}
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'user_id' => $this->user_id,
'visible' => $this->visible,
'sorting' => $this->sorting,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'slug', $this->slug])
->andFilterWhere(['like', 'image', $this->image])
->andFilterWhere(['like', 'description', $this->description])
->andFilterWhere(['>=', 'created_at', $this->date_from ? $this->date_from : null])
->andFilterWhere(['<=', 'created_at', $this->date_to ? $this->date_to : null])
->andFilterWhere(['>=', 'updated_at', $this->date_upd_from ? $this->date_upd_from : null])
->andFilterWhere(['<=', 'updated_at', $this->date_upd_to ? $this->date_upd_to : null]);
return $dataProvider;
}
Так что мне нужно получить список игр через таблицу user_game, где user_id = текущий идентификатор пользователя, game_id = идентификатор игры. Пожалуйста, помогите.