Pagerfanta icon indicating copy to clipboard operation
Pagerfanta copied to clipboard

Empty getCurrentPageResults

Open akorz opened this issue 6 years ago • 6 comments

Hello,

I have code

        $qb = $this->createQueryBuilder('country');
        $adapter = new DoctrineORMAdapter($qb);
        $this->pagerfanta = new Pagerfanta($adapter);
        $this->pagerfanta->setMaxPerPage(10);
        $this->pagerfanta->setCurrentPage(1);

        var_dump($this->pagerfanta->getNbResults());
        var_dump($this->pagerfanta->getCurrentPageResults());

the result

int(242)
object(ArrayIterator)#12190 (1) { ["storage":"ArrayIterator":private]=> array(0) { } }

But I see following lines in dev.log

[2018-10-09 17:37:43] doctrine.DEBUG: SELECT DISTINCT id_0 FROM (SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.iso_code AS iso_code_2, c0_.phone_code AS phone_code_3, c0_.deleted_at AS deleted_at_4 FROM countries c0_) dctrn_result LIMIT 10 [] []
[2018-10-09 17:37:43] doctrine.DEBUG: SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.iso_code AS iso_code_2, c0_.phone_code AS phone_code_3, c0_.deleted_at AS deleted_at_4 FROM countries c0_ WHERE c0_.id IN (?) [["[object] (App\\Domain\\Country\\ValueObject\\CountryId: 0042840f-843e-457d-9250-b1e22d8d6d5e)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 01c4f446-48a9-413f-9225-7138c0e39f98)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 029bed5c-35f2-4c7d-812c-7d7d3d886be1)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 02c0460d-8902-4cf7-a070-e6404f321c25)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 0315d760-5dea-412e-8242-7eceb7373375)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 033d07bb-c4ce-4166-991b-a5441bcf2b7e)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 035ce32a-3b21-40e8-ae58-ee3a15fd6c71)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 054f444e-c8d2-48ad-a058-5bd94ff8a133)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 05bafdf7-a31e-4d84-8db7-a03f3bb0d670)","[object] (App\\Domain\\Country\\ValueObject\\CountryId: 0873c562-db8a-4189-af35-82d5d80b7fe9)"]] []
[2018-10-09 17:37:43] doctrine.DEBUG: SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_0 FROM (SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.iso_code AS iso_code_2, c0_.phone_code AS phone_code_3, c0_.deleted_at AS deleted_at_4 FROM countries c0_) dctrn_result) dctrn_table [] []

So looks like something happens. At least I get right NB count. But empty getCurrentPageResults. May be problem that my Id is CountryID UUID based?

akorz avatar Oct 09 '18 18:10 akorz

Somehow it started to work with

$adapter = new DoctrineORMAdapter($qb, true, false);

What is it?

akorz avatar Oct 11 '18 19:10 akorz

That's odd. Does it still work if you do this?

$adapter = new DoctrineORMAdapter($qb, true, null);

(i.e. changing false to null)

sampart avatar Oct 15 '18 14:10 sampart

@sampart can confirm it doesn't work with null. Had the same issue. It works with false though. Can anyone explain?

mcbuckets avatar Oct 26 '18 08:10 mcbuckets

@mcbuckets Thanks for checking. I've not had a time to check on my side :(

akorz avatar Oct 26 '18 08:10 akorz

If anyone wants a bit of context on Output Walkers, https://github.com/whiteoctober/Pagerfanta/issues/220 may help.

sampart avatar Oct 29 '18 15:10 sampart

I'm afraid I don't understand Doctrine's internals well enough to explain this issue, sorry! @akorz I think you may be on the right lines when you say it's due to the specifics of your model. You could also experiment with passing a more configured querybuilder rather than the standard one you get by only passing an alias to createQueryBuilder.

sampart avatar Oct 29 '18 15:10 sampart