Skip to content

[bug] Phalcon\Paginator\Adapter\QueryBuilder count is not accurate #2411

Closed
@zhouyl

Description

(Sorry, i am chinese! Too bad English.)

When QueryBuider presence group by, count is not accurate.

My Code

class MyQueryBuilder extends \Phalcon\Paginator\Adapter\QueryBuilder
{

    public function getPaginate()
    {
        $paginate = parent::getPaginate();

        $builder = $this->getQueryBuilder();

        if ($group = $builder->getGroupBy()) {
            $result = $builder->columns('count(distinct ' . $group . ') as total')
                ->groupBy(null)
                ->getQuery()
                ->execute()
                ->getFirst();
            $paginate->total_items = $result->total;
            $paginate->total_pages = ceil($paginate->total_items / $this->getLimit());
        }

        return $paginate;
    }

}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions