gpt4 book ai didi

symfony - KnpPaginator 和 native 查询

转载 作者:行者123 更新时间:2023-12-02 16:13:27 24 4
gpt4 key购买 nike

我在 Symfony2 项目中使用 KnpPaginatorBundle。当我尝试将 Doctrine 2 native 查询传递给分页器实例时,出现错误:

One of listeners must count and slice given target

有没有人有一些关于某些 native 查询的正确实现的示例?

在 bundle 的文档中,我看到示例( https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/custom_pagination_subscribers.md ),但仅适用于文件系统,我不知道如何将其转换为数据库查询。

你能帮忙吗?

编辑

我的查询:

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;

和表格:

author (id, first_name, last_name)
books (id, title, rate, author_id)

最佳答案

不幸的是,该 bundle 不适用于 native 查询。最好的解决方案(尽管它加载了许多不需要的行)是从查询中获取结果并对结果数组进行分页。

大约五分钟前我遇到了这个问题,引用:https://groups.google.com/forum/#!msg/symfony2/cgYHeKej7jc/y9dHX-qvTU4J

关于symfony - KnpPaginator 和 native 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11058130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com