Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Problems trying to use 'sort' method in a Document Repository
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Matias Montenegro  
View profile   Translate to Translated (View Original)
 More options Feb 12, 11:45 am
From: Matias Montenegro <matiasmmontene...@gmail.com>
Date: Sun, 12 Feb 2012 13:45:56 -0300
Local: Sun, Feb 12 2012 11:45 am
Subject: Problems trying to use 'sort' method in a Document Repository

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'=> $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'=>
$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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ezequiel Rabinovich  
View profile  
 More options Feb 12, 11:51 am
From: Ezequiel Rabinovich <erabinov...@gmail.com>
Date: Sun, 12 Feb 2012 13:51:52 -0300
Local: Sun, Feb 12 2012 11:51 am
Subject: Re: [doctrine-user] Problems trying to use 'sort' method in a Document Repository

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matias Montenegro  
View profile  
 More options Feb 12, 12:05 pm
From: Matias Montenegro <matiasmmontene...@gmail.com>
Date: Sun, 12 Feb 2012 14:05:55 -0300
Local: Sun, Feb 12 2012 12:05 pm
Subject: Re: [doctrine-user] Problems trying to use 'sort' method in a Document Repository

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')->equals($user->getId())
            ->sort('created', 'asc')
            ->getQuery()
            ->execute();

}

Thank you very much Ezequiel

2012/2/12 Ezequiel Rabinovich <erabinov...@gmail.com>

--
Matias

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ezequiel Rabinovich  
View profile  
 More options Feb 12, 12:08 pm
From: Ezequiel Rabinovich <erabinov...@gmail.com>
Date: Sun, 12 Feb 2012 14:08:03 -0300
Local: Sun, Feb 12 2012 12:08 pm
Subject: Re: [doctrine-user] Problems trying to use 'sort' method in a Document Repository

Great :), I'm glad to help.

Cheers

--
Ezequiel Rabinovich
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Sunday 12 de February de 2012 at 14:05, Matias Montenegro wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »