Код: Выделить всё
public function getPrice(){
return $this->hasOne(Price::className(),['id'=>'id_price']);
}
Я так получаю товары
Код: Выделить всё
$goods=Goods::find()->with('price');
Затем я использую Listviews.
Код: Выделить всё
public function getPrice(){
return $this->hasOne(Price::className(),['id'=>'id_price']);
}
Код: Выделить всё
$goods=Goods::find()->with('price');
Код: Выделить всё
$goods=Goods::find()->joinWith('price')->orderBy(['price.id'=>SORT_DESC]);
а без joinWith нельзя ?vitalik1183 писал(а): ↑2017.06.28, 16:17Код: Выделить всё
$goods=Goods::find()->joinWith('price')->orderBy(['price.id'=>SORT_DESC]);
Я так понимаю, что сортировать надо по цене а не по её id.Sergalas писал(а): ↑2017.06.28, 16:42а без joinWith нельзя ?vitalik1183 писал(а): ↑2017.06.28, 16:17Код: Выделить всё
$goods=Goods::find()->joinWith('price')->orderBy(['price.id'=>SORT_DESC]);
Код: Выделить всё
Prices::find()->with('goods')->orderBy('price DESC');
Код: Выделить всё
$query = Goods::find()->joinWith('price p');
Код: Выделить всё
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'attributes' => [
'id_price' => [
'asc' => ['p.price' => SORT_ASC, 'product_name' => SORT_ASC],
'desc' => ['p.price' => SORT_DESC, 'product_name' => SORT_ASC],
],
...
],
'defaultOrder' => ['id_price' =>SORT_DESC]
]
]);