yii对oneToMany关联对象进行排序

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getNews()
    {
        return $this->hasMany(News::className(), ['category' => 'id'])->orderBy('created_at DESC');
    }
$news = Category::findOne($category_id)->news;

你可能感兴趣的:(yii对oneToMany关联对象进行排序)