> Thanks for the clue, but I wanted to do it inside the repositoy, so I ended up doing it this way:
> function listProducts($user){
> return $this->createQueryBuilder()
> ->field('user.id (http://user.id)')->equals($user->getId())
> ->sort('created', 'asc')
> ->getQuery()
> ->execute();
> }
> Thank you very much Ezequiel
> 2012/2/12 Ezequiel Rabinovich <erabinov...@gmail.com (mailto:erabinov...@gmail.com)>
> > The findBy magic method already returns a cursor, not a query. Try this:
> > $dm->createQueryBuilder('Products')
> > ->field('id')->equals($user->getId())
> > ->sort('created', 'asc')
> > ->getQuery()
> > ->getSingleResult();
> > Cheers
> > --
> > Ezequiel Rabinovich
> > Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
> > On Sunday 12 de February de 2012 at 13:45, Matias Montenegro wrote:
> > > Hello, I'm using Doctrine2 with MongoDB, and I'm having problems when I try to add a sort statement to a query.
> > > I'm doing it in ProductRepository.php I have:
> > > function listProducts($user){
> > > return $this->findBy(array('user.id (http://user.id)'=> $user->getId()));
> > > }
> > > Then in my template I have:
> > > foreach($cursor as $product)
> > > echo $product->getName();
> > > And it works fine.
> > > But when I change it to add the sort method:
> > > function listProducts($user){
> > > return $this->findBy(array('user.id (http://user.id)'=> $user->getId()))->sort('created', 'asc');
> > > }
> > > I get:
> > > ErrorException: Warning: Invalid argument supplied for foreach() in /home/matias/workspace/proyecto/vendor/doctrine/mongodb-odm/lib/Doctrine/OD M/MongoDB/Persisters/DocumentPersister.php line 671I know I'm doing something wrong, so which is the right way to add this method in a repository??
> > > --
> > > Matias
> > > --
> > > You received this message because you are subscribed to the Google Groups "doctrine-user" group.
> > > To post to this group, send email to doctrine-user@googlegroups.com (mailto:doctrine-user@googlegroups.com).
> > > To unsubscribe from this group, send email to doctrine-user+unsubscribe@googlegroups.com (mailto:doctrine-user+unsubscribe@googlegroups.com).
> > > For more options, visit this group at http://groups.google.com/group/doctrine-user?hl=en.
> > --
> > You received this message because you are subscribed to the Google Groups "doctrine-user" group.
> > To post to this group, send email to doctrine-user@googlegroups.com (mailto:doctrine-user@googlegroups.com).
> > To unsubscribe from this group, send email to doctrine-user+unsubscribe@googlegroups.com (mailto:doctrine-user%2Bunsubscribe@googlegroups.com).
> > For more options, visit this group at http://groups.google.com/group/doctrine-user?hl=en.
> --
> Matias
> --
> You received this message because you are subscribed to the Google Groups "doctrine-user" group.
> To post to this group, send email to doctrine-user@googlegroups.com (mailto:doctrine-user@googlegroups.com).
> To unsubscribe from this group, send email to doctrine-user+unsubscribe@googlegroups.com (mailto:doctrine-user+unsubscribe@googlegroups.com).
> For more options, visit this group at http://groups.google.com/group/doctrine-user?hl=en.