I want to execute this query:
$topics = ForumTopic::find()
->with([
'lastPost' => function($query) {
$query->select(['id', 'ctime']);
},
])
->orderBy('lastPost.ctime DESC')
->all();
Relation declared in ForumTopic like this:
public function getLastPost()
{
return $this->hasOne(ForumPost::className(), ['id' => 'lastPostId']);
}
But my query fails (because yii2 make all queries separate and don't join tables). Is any way to achive my purpose by yii2 activeRecord?