Leszek Wiesner
Leszek Wiesner

Reputation: 155

Yii2 ActiveDateProvider and joinWith hasMany relation

I use ActiveDateProvider and I use query like this:

Foo::find()->joinWith('relation');

And Foo's relation is hasMany, so there is more than one record joined to every Foo.

In that case the pagination doesn't work properly (for example in GridView it says: Showing 1-6 of 17 items. even though the pagination is set to 10 and there are actually only 10 records of Foo in the database)

What can I do to make the pagination work properly (counting only Foo, not the joined records)

Upvotes: 0

Views: 657

Answers (1)

Kamran Ali
Kamran Ali

Reputation: 5954

Sorry for late reply, but I recently stuck into the issue and found out that distinct() will do the trick for you.

Foo::find()->joinWith('relation')->distinct();

Upvotes: 0

Related Questions