Order relationships (association) between entities with symfony/doctrine
I want just share a little something today.
Sometimes, you spend time to try to achieve something, and when you finally manage to do it, you see, the best practice, the helper, the proxy class, you see the real and beautiful solution !
Today is one of this day for me, I need to order a relationship between to entities, managed by doctrine, in my Symfony project.
But instead of searching in the doc (RTFM… always) I have tried and lost my time before I search and found.
Ddoctrine is clearly an amazing solution, and *of course* my use case is already manage by an annotation :
Short (copied from doc):
[pastacode lang= »php » manual= »%2F**%20%40Entity%20**%2F%0Aclass%20User%0A%7B%0A%2F%2F%20…%0A%0A%2F**%0A*%20%40ManyToMany(targetEntity%3D%22Group%22)%0A*%20%40OrderBy(%7B%22name%22%20%3D%20%22ASC%22%7D)%0A**%2F%0Aprivate%20%24groups%3B%0A%7D%0A%0A%2F*%20With%20symfony%20%20*%2F%0Ause%20Doctrine%5CORM%5CMapping%20as%20ORM%3B%0A%0A%2F**%20%40Entity%20**%2F%0Aclass%20User%0A%7B%0A%2F%2F%20…%0A%0A%2F**%0A*%20%20*%40ORM%5CManyToMany(targetEntity%3D%22Group%22)%0A*%20%40ORM%5COrderBy(%7B%22name%22%20%3D%20%22ASC%22%7D)%0A**%2F%0Aprivate%20%24groups%3B%0A%7D%0A » message= » » highlight= » » provider= »manual »/]
Doctrine official :
Order relationship between entities
Yes ! Just like that