Order of array collection

Viewed 40

If I have a one-to-many/many-to-one relationship between shop entity and product entity. and I use $products = $shop->getProducts()->toArray(); then dump($products); the products are retrieved by the ascending order of Ids (primary key) and this is the behaviour that I want. I just want to know if that will always be the case because I always want the products to be retrieved in this order : from smallest to biggest ID and I want to know if getProducts() always returns the array this way or I should create a Repo function. I checked the query that is executed and it doesn't have any orderBy attribute so is sort by Id ASC the default one?

0 Answers
Related