5

I use KnpPaginatorBundle in my Symfony2 project. When i try to pass a Doctrine 2 native query to paginator instance, I got error:

One of listeners must count and slice given target

Have anyone some example of correct implementation of this for some native query?

In bundle's documentation I see example (https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/custom_pagination_subscribers.md) but only for filesystem and I don't know how to translate this to db query.

Can you help?

EDIT

my query:

SELECT a.*, highest_rated_book.*
  FROM authors a
  LEFT JOIN (SELECT * FROM books b ORDER BY b.rate DESC) AS highest_rated_book
  ON a.id = highest_rated_book.author_id
  GROUP BY highest_rated_book.author_id
  ORDER BY a.id;

and tables:

author (id, first_name, last_name)
books (id, title, rate, author_id)
Matteo
  • 37,680
  • 11
  • 100
  • 115
shinji
  • 55
  • 1
  • 4

1 Answers1

4

Unfortunately, the bundle doesn't work with native queries. The best solution (although it loads many unneeded rows) is to get the result from the query and paginate the result array.

I ran into this problem approximately five minutes ago, reference: https://groups.google.com/forum/#!msg/symfony2/cgYHeKej7jc/y9dHX-qvTU4J

Lusitanian
  • 11,012
  • 1
  • 41
  • 38
  • 1
    I don't think that this can be considered "the best solution". The best solution is to handle it differently. We have tables with 10s of millions of rows which need paging. – Luke Cousins Apr 08 '19 at 15:10