Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I set the initial value of the First Result in query Builder. Why didn't I add Pagerfanta into the Offset when using Pagerfanta #263

Open
tb07 opened this issue Nov 30, 2018 · 1 comment

Comments

@tb07
Copy link

tb07 commented Nov 30, 2018

public function getAuthorProducts($uuid)
{
    $queryBuilder = $this->createQueryBuilder('o')
        ->addSelect('author')
        ->innerJoin('o.author', 'author')
        ->andWhere("author.uuid=:uuid")
        ->andWhere("o.enabled=:enabled")
        ->andWhere("o.isShow=:isShow")
        ->setParameter("isShow", true)
        ->setParameter("enabled", true)
        ->setParameter("uuid", $uuid)
        ->setFirstResult(5)
    ;

    return $this->getPaginator($queryBuilder);
}

I print the Paginator
image

Query Builder has FirstResult in it

But FirstResult didn't work in the end

I notice that "Pagerfanta/Pagerfanta, "line 316 is not going to fetch the initial FirstResult

private function getCurrentPageResultsFromAdapter()
{
    $offset = $this->calculateOffsetForCurrentPageResults();
    $length = $this->getMaxPerPage();

    return $this->adapter->getSlice($offset, $length);
}

private function calculateOffsetForCurrentPageResults()
{
    return ($this->getCurrentPage() - 1) * $this->getMaxPerPage();
}
@sampart
Copy link
Collaborator

sampart commented Dec 5, 2018

Hi @tangbingbing, thanks for getting involved.

The DoctrineORM adapter, which I think is the one you're using, actually uses setFirstResult itself behind the scenes, so I guess that's why your setting of it is being ignored.

If we wanted to support starting from an arbitrary offset, we'd need to modify the adapter method and get people to use a new method on Pagerfanta to set start point rather than doing it directly in the querybuilder, I think.

Anyway, regardless of exactly how we do it, this is quite a major change, I'm afraid. Could you explain more about your use case here? That'll help us work out whether it's worth suggesting you make a Pull Request for this change or whether it's not worth incorporating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants