cakePHP 使用左连接分页会导致页数不正确
我在 cakePHP 分页方面遇到问题,特别是当我进行左连接时。返回 6 行,分页限制为 3,它应该计算 2 页,但它计算 3 页,最后一页为空白。这是我传递给分页的选项数组:
Array ( [fields] => Array ( [0] => DISTINCT Video.id, Video.thumbnail_img, Video.title, Video.description, Video.tags, Video.views, Video.date, (( SELECT COUNT(Rating.id) FROM ratings AS Rating WHERE Rating.rating = 1 AND Rating.video_id = Video.id ) - ( SELECT COUNT(Rating.id) FROM ratings AS Rating WHERE Rating.rating = 0 AND Rating.video_id = Video.id ) ) AS avgRating ) [joins] => Array ( [0] => Array ( [table] => ratings [alias] => Rating [type] => LEFT [conditions] => Array ( [0] => Rating.video_id = Video.id ) ) ) [order] => Array ( [avgRating] => DESC ) )
有什么想法为什么会发生这种情况吗?我不确定是否有其他方法可以在不使用连接的情况下获得我想要的结果,但我敢打赌这就是导致问题的原因。
任何建议将不胜感激。谢谢!
I'm having an issue with cakePHP pagination, specifically when I do a left join. There are 6 rows returned, and with a pagination limit of 3, it should calculate 2 pages, but it calculates 3 pages, with the last page being blank. Here is the options array I'm passing to paginate:
Array ( [fields] => Array ( [0] => DISTINCT Video.id, Video.thumbnail_img, Video.title, Video.description, Video.tags, Video.views, Video.date, (( SELECT COUNT(Rating.id) FROM ratings AS Rating WHERE Rating.rating = 1 AND Rating.video_id = Video.id ) - ( SELECT COUNT(Rating.id) FROM ratings AS Rating WHERE Rating.rating = 0 AND Rating.video_id = Video.id ) ) AS avgRating ) [joins] => Array ( [0] => Array ( [table] => ratings [alias] => Rating [type] => LEFT [conditions] => Array ( [0] => Rating.video_id = Video.id ) ) ) [order] => Array ( [avgRating] => DESC ) )
Any ideas why this is happening? I'm not sure of any other way to get the results I want without using the join, but I'm betting that's what's causing the problem.
Any suggestions would be appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
愚蠢的问题 - 在这种情况下甚至不需要连接。无需连接即可获得相同的结果,因为子查询可以自行评估。对于本示例来说,这是可以的,但可能还有其他示例,其中需要连接并且计数错误确实存在。不管怎样,我的问题已经解决了!
Foolish problem - in this case the join isn't even necessary. The same results are achieved without the join, since the sub-queries can be evaluated on their own. For this example, it's ok, but there may be further examples where a join is necessary and the count error does persist. Either way, my problem is solved!