Question

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)
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top