English 中文(简体)
cakeHP使用左联接进行分页会导致页数不正确
原标题:cakePHP paginate with left join causes incorrect number of pages

我对cakeHP分页有问题,特别是当我执行左联接时。返回了6行,在分页限制为3的情况下,它应该计算2页,但它计算3页,最后一页为空。以下是我传递给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
        )

)

你知道为什么会发生这种事吗?我不确定是否有其他方法可以在不使用联接的情况下获得我想要的结果,但我打赌这就是问题的原因。

如有任何建议,我们将不胜感激。谢谢

最佳回答

愚蠢的问题——在这种情况下,联接甚至没有必要。由于可以单独评估子查询,因此在没有联接的情况下也可以获得相同的结果。对于这个例子,这是可以的,但可能还有其他例子,其中连接是必要的,并且计数错误仍然存在。不管怎样,我的问题都解决了!

问题回答

暂无回答




相关问题
Pagination problem

I m using this code for my pagination, and I d like the user s choice to be persistent throughout the site (this has been solved so far)...the only problem now is that the session variable now is ...

mod rewrite problem with 2 parameters

I m trying to rewrite the categoy file of my shop system, I also integrated a pagination so I need to rewrite 2 parameters. it almost works, otherwise I wouldn t be posting in here this is the ...

Issues with pagination in ASP.NET MVC

I am trying to implementation the same pagination that is used in the NerdDinner ASP.NET. I am receiving the following error in my view, whenever the pagination starts to kick in. "A route named ...

Pagination in SQL Server

How do i limit the result of a query (in my case about 60K rows) and select only from the X row to the Y row? If I use ROW_NUMBER() I don t like my query because it involves 2 select queries .. one ...

Cakephp 1.2 Paginator and PassedArgs

Problem: when i have a search resultset with pagination, the links next, prev and numbers do not keep the search parameters. Seems to be a common problem. I searched everywhere on the internet, and ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

热门标签