whiteoctober / Pagerfanta

Pagination for PHP.
Other
1.59k stars 2 forks source link

Empty getCurrentPageResults #254

Open akorz opened 5 years ago

akorz commented 5 years ago

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 commented 5 years ago

Somehow it started to work with

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

What is it?

sampart commented 5 years ago

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

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

(i.e. changing false to null)

mcbuckets commented 5 years ago

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

akorz commented 5 years ago

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

sampart commented 5 years ago

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

sampart commented 5 years ago

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.