>From the code above it looks like you aren't using the object alias in
the orderby call.  In your example above, it should be
orderby('c.create_at ASC')
Here is how I would write that query:

$q =$this->createQuery('c')
       ->join('c.User')
       ->where('c.auction_id = ?',array($auction_id))
       ->orderBy('c.created_at ASC')
       ->limit(20);

AFAIK, that should work, and it doesn't require a subquery, note the
c.created in the orderBy() function.

HTH,
Casey



On May 5, 2:03 am, Joel WURTZ <[email protected]> wrote:
> Hello,
>
> I try to get the 20 last record of a table in asc order, it is simply done
> with a sql query but when i try to do it with doctrine i got many problems
>
> I first tried to get them in desc order and after reverse the collection in
> doctrine, but the only way is to get the key values reverse it (with
> array_reverse) and then get each record with a loop on this array. But i
> found this solution ugly so i try to it in sql :
>
> $query = $this->createQuery('c')
>             ->innerJoin('c.User')
>             ->where('c.auction_id = ? AND c.id IN (SELECT c2.id FROM Chat c2
> WHERE c2.auction_id = ? ORDER BY c2.created_at DESC LIMIT 0, 20)',
> array($auction_id, $auction_id))
>             ->orderBy('created_at ASC');
>
> Problem : Doctrine cut my subquery, and remove the limit part, so my
> subquery is useless (^^)
> I try also to do a reverse directly on Doctrine Collection but that doesn't
> work
>
> If you have a better solution than the first one i'm ready to take it ....
>
> Ty,
>
> --
> Joel WURTZ
> Etudiant ingénieur à EISTI PAU
> 06 23 64 03 55
> 2 passage des alliées
> 64000 Pau
>
> --
> If you want to report a vulnerability issue on symfony, please send it to 
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/symfony-users?hl=en

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to