A tailor-made query

Exercise 3 of 6 in chapter 2 · 150 XP · 5 objectives checked by tests

Topics covered: QueryBuilderDQLParameters

The broke adventurers are complaining: there's no way to tell what six gold pieces will buy. And Gorm would like the “dish of the day” to be the cheapest specialty, to draw in the customers.

findBy() is no longer enough: you need to write your own queries. The Cuisine service, the controller and the template are ready. They call three methods of PlatRepository… which return empty lists for now.

Your mission

In PlatRepository, write with the QueryBuilder:

  1. findParPrixCroissant() (by increasing price): all the dishes, from cheapest to most expensive;
  2. findSpecialites(): only the specialties, from cheapest to most expensive;
  3. findPourUnBudget(float $budget) (for a budget): the dishes whose price does not exceed the budget, from cheapest to most expensive.

Try /menu, then /menu?budget=6 in the preview.

Reminder

The QueryBuilder produces DQL: it talks about entities and properties (p.prix), not tables and columns. And a value coming from outside always goes through a parameter (:budget), never through concatenation.