views:

163

answers:

1

Hi everybody,

I'm using Symfony 1.4 + Doctrine 1.1.

I have a schema with a one-to-many relation. Let's say A has many B, I ask for all the B's of A as follow: $a->b This returns a Doctrine_Collection.

What I want its a way to tell doctrine to give me all the B's of A sorted by a particular attribute of B.

I don't want to re-write the query, I just want to tell the accesor getBs() to sort as I wanted.

Is this possible? any idea?

Tanks in advance!! Alejandro.

+2  A: 

What you are looking for is http://www.doctrine-project.org/blog/cookbook-recipe-relation-dql-behavior

It is an example behavior (written by Jon Wage, lead dev of Doctrine), that allows you to include DQL statements into a relation declaration. It's all described in the blogpost so I'll just say I'd recommend putting everything in your lib/doctrine/ (create it if needed) and there you are!

Geoffrey Bachelet
Awesome!, just what I needed.Many thanks Geoffrey
Alejandro G.
This solution doesn't work for lazy-loading a relation, only for full DQL Doctrine_Querys (according to a comment by the original author). So, while its useful and nice, it doesn't solve the problem that $a->Bs or $a->getBs() will not produce SQL having an orderBy.
Domster