A place for every dish

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

Topics covered: ManyToOneOneToManyRelations

With Bruna's inventions, the menu keeps growing… and nobody can find anything anymore: the Captain's Grog sneaks in between two stews. Gorm wants a menu sorted by category: main courses, sides, drinks.

Your mission

  1. Map the Categorie (category) entity (categorie table): a generated id, a unique nom (name, 50 characters), a position (the display order on the menu).
  2. Link the two entities:
    • every dish belongs to a category, and it's required;
    • a category knows its dishes, from cheapest to most expensive.
  3. Sort the menu: for each category (the controller already passes them in position order), a <section class="categorie"> with an <h2> and the <ul class="plats"> list of its dishes.

The properties, getters and setters are written: the mapping and the template are up to you. The menu filtered by budget (?budget=) stays a simple list.

The console

The loading command fails as long as Categorie is not an entity: that's expected. Once the mapping is written, run again:

doctrine:schema:update --force
app:charger-carte

Reminder

In a relation, the ManyToOne side is the owning side: it holds the foreign key (categorie_id). The OneToMany side is the inverse side: it exists for navigation (categorie.plats) and is declared with mappedBy.