Код: Выделить всё
public function getPosts()
{
return $this
->hasMany(Posts::className(), ['id_user' => 'id'])
->orderBy(['posts.id' => SORT_DESC])
;
}
Код: Выделить всё
User::find()
->with('posts')
->where(['active_user' => 1])
->limit(10)
->all()
Код: Выделить всё
public function getPosts()
{
return $this
->hasMany(Posts::className(), ['id_user' => 'id'])
->orderBy(['posts.id' => SORT_DESC])
;
}
Код: Выделить всё
User::find()
->with('posts')
->where(['active_user' => 1])
->limit(10)
->all()
Код: Выделить всё
SELECT user.*, IFNULL((SELECT MAX(posts.created) FROM posts WHERE posts.user_id=user.id),0) as post_date
FROM user
WHERE user.active_user = 1
ORDER BY post_date
LIMIT 10