Reputation: 283
I'm working with Yii2 and I can't solve it out. I need to OrderBy first table's rows by the third table's column.
First table: user [id, ....]
Second table: info [id, user_id, city_id, ...]
Third table: city [id, title, latitude, longitude]
models/User:
public function getInfo()
{
return $this->hasOne(InfoClear::className(), ['user_id' => 'id']);
}
models/Info
public function getCity()
{
return $this->hasOne(City::className(), ['id' => 'city_id']);
}
models/RecommendedSearch
$query = User::find()->joinWith(['info']);
Also I have to connect somehow 'city' table
Upvotes: 0
Views: 95
Reputation: 1281
Somthing like this
User::find()->joinWith(['info' => function(\yii\db\ActiveQuery $q){
$q->joinWith('city');
}]);
Or try
User::find()->with('info.city')->all();
Upvotes: 1