How to OrderBy on OneToMany/ManyToOne

In the Product entity you just need to add the orderBy to the ingredients relation

/**
 * @ORM\OrderBy({"some_attribute" => "ASC", "another_attribute" => "DESC"})
 */
private $ingredients;

With PHP 8 attributes:

#[ORM\OrderBy(['some_attribute' => 'ASC', 'another_attribute' => 'DESC'])]
private $ingredients;

Leave a Comment