Answer the question
In order to leave comments, you need to log in
How to sort ActiveRecord with with in yii1 by category sort order?
Good afternoon,
There are 2 tables (products and category) and 2 models( Products and Category )
products
----------
id
name
category_id
=========
category
------- ---
id
name
order_sort (int)
=========
class Products extends ActiveRecord{
...
public function relations() {
return [
'category' => [self::BELONGS_TO, 'Category', 'category_id'],
];
}
$model = Products::model()->with(
'category',[
'order' => 'order_sort ASC'
] )->findAll();
Answer the question
In order to leave comments, you need to log in
Offhand, using CDbCriteria:
$criteria = new CDbCriteria;
$criteria->with=['category']
$criteria->order='category.order_sort ASC';
$model = Products::model()->findAll($criteria);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question