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

Not showing when using doctrine odm with prime parameter. #326

Open
veego opened this issue Aug 26, 2015 · 6 comments
Open

Not showing when using doctrine odm with prime parameter. #326

veego opened this issue Aug 26, 2015 · 6 comments

Comments

@veego
Copy link

veego commented Aug 26, 2015

Hi,
KNP paginator is great, but I have one issue with it. If I make query with prime->(true), all working except pagination links is not rendered. Here is my query:

$qb = $dm->createQueryBuilder('AppBundle\Document\Post');
$qb->field('forum')->references($document)
    ->field('author')->prime(true)
    ->sort('created', 'asc');

When I remove ->field('author')->prime(true) it's show again, but it's not good because each author of post need separate db query.

@veego
Copy link
Author

veego commented Aug 26, 2015

I do it other way, pass ArrayCollection of posts to paginator, and in forum document I add custom repository method with prime. Now working, but I dont know wy because there are the same db queries as before.

//Controller
$posts = $forum->getPosts();
...
$paginator->paginate($posts,....


//Document
/**
 * @ODM\ReferenceMany(targetDocument="Post", repositoryMethod="findPosts", simple=true)
 */
protected $posts;

@veego
Copy link
Author

veego commented Aug 27, 2015

After all, not working as expected, sorting very strange, first one user with posts 'asc' then second etc... and Forum document must have array collection with Posts Id's otherwise pager don't show.
Switched to pagerfanta, works as expected.

@sirian
Copy link

sirian commented Dec 29, 2015

As a workaround you could do reference priming manually. For example add BaseRepository class with method

   public function primeReferences($items, $fields)
    {
        $dm = $this->getDocumentManager();
        $primer = new ReferencePrimer($dm, $dm->getUnitOfWork());
        foreach ($fields as $field) {
            $primer->primeReferences($this->getClassMetadata(), $items, $field);
        }
    }

and then simply call in controller

$repository->primeReferences($pagination->getItems(), ['author']);

@amcsi
Copy link

amcsi commented Jul 18, 2017

This issue is very relevant: doctrine/mongodb-odm#1283

@polc
Copy link
Contributor

polc commented Sep 15, 2017

Hello @veego sorry for the late response, has your issue been fixed?

@alexseif
Copy link

Hello, I'm currently facing this issue, is there a resolution?
Can I somehow provide the count query to the paginator?

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

No branches or pull requests

5 participants