yii对oneToMany关联对象进行排序
2016-06-14 本文已影响13人
小马飞驰bnb
/**
* @return \yii\db\ActiveQuery
*/
public function getNews()
{
return $this->hasMany(News::className(), ['category' => 'id'])->orderBy('created_at DESC');
}
$news = Category::findOne($category_id)->news;