S
S
seacjs2020-01-21 14:55:54
Yii
seacjs, 2020-01-21 14:55:54

Why does Yii2 ListView spawn new items in the list?

There is a Product model and a Price associated with it

public function getPrices()
    {
        return $this->hasMany(Price::class, ['product_id' => 'id']);
    }

I'm trying to implement such a query and display it through a ListView
$query = Product::find()
        ->joinWith('prices', true , 'LEFT JOIN')
        ->orderBy(['price.price' => SORT_DESC]);

$dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

As a result, it displays pagination on two pages. On the first 4 products, and on the second 1 product (a copy of one of the first).
I do a check and displays everything correctly, 4 products. If you add conditions for displaying a product with a price from / to, then the ListView duplicates them even more ... What could be the problem?
VarDumper::dump($query->all,10,1);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Izmailov, 2019-04-15
@nnkrasovok

['surname', 'on' => ['register', 'create', 'update']]

M
Maxim, 2020-01-21
@seacjs

Try:

$query = Product::find()
        ->joinWith('prices', true , 'LEFT JOIN')
        ->orderBy(['price.price' => SORT_DESC])
        ->distinct();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question