In various cases I need to sort a Doctrine\\Common\\Collections\\ArrayCollection according to a property in the object. Without finding a method doing that righ
If you have an ArrayCollection field you could order with annotations. eg:
Say an Entity named Society has many Licenses. You could use
/**
* @ORM\OneToMany(targetEntity="License", mappedBy="society")
* @ORM\OrderBy({"endDate" = "DESC"})
**/
private $licenses;
That will order the ArrayCollection by endDate (datetime field) in desc order.
See Doctrine documentation: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#orderby