Equivalent with ActiveQuerycan be like this:
Camp::find()
->select(['city_id', 'state_id', 'city_name'])
->distinct()
->joinWith('city')
->where([
'state_id' => 5,
'status' => 1,
])
->orderBy(['city_name' => SORT_ASC])
->all();
And add a relation to the model Camp:
public function getCity()
{
$this->hasOne(City::className(), ['state_id' => 'state_id']);
}
You can find the documents in the Active Record section :
source
share