Chapter 8 of the Symfony for PHP developers track

Back to the cellar

6 exercises · 1,650 XP · about 4 h 45 min

This chapter works on: Migrationsdoctrine:migrations:diffdoctrine:migrations:migrateup() and down()Data migrationdoctrine:schema:validateDefault valuedown()ManyToManyOwning sideInverse side#[ORM\OrderBy]Join tableN+1 queriesLazy loadingJoinaddSelectleftJoinPaginationPaginatorsetFirstResultsetMaxResults#[MapQueryParameter]Debugging

The chapter's exercises

  1. The first migration

    Exercise 1 · 250 XP · 5 objectives checked by tests

    Big news: the tavern's website is going live for real. It will run on a server, with a database that keeps the reservations, the reviews and the staff accounts.

    Migrationsdoctrine:migrations:diffdoctrine:migrations:migrateup() and down()

  2. Keep the cellar full

    Exercise 2 · 260 XP · 5 objectives checked by tests

    The website has been running for a week, and Bruna has a request: show on each dish page how many portions are left today. Pippin has already added the field to the Plat (dish) entity (portions, 10 by default). All that's left is to “just” update the database.

    Data migrationdoctrine:schema:validateDefault valuedown()

  3. The pantry

    Exercise 3 · 260 XP · 5 objectives checked by tests

    Bruna wants to show the ingredients of each dish: travelers have allergies, and the Fire pepper has already sent a dwarf to the infirmary. Pippin has made a start: the Ingredient entity exists, and he wrote the command that tidies the pantry, app:garnir-les-plats (stock the dishes). All that's left is to connect it all.

    ManyToManyOwning sideInverse side#[ORM\OrderBy]Join table

  4. The Friday rush

    Exercise 4 · 270 XP · 5 objectives checked by tests

    Friday night, and the tavern is packed. Bruna has added the Friday feast to the menu, twenty-four dishes, and the ingredients now show on the menu too. The result: the /menu page crawls, and the database server is smoking harder than the Fire pepper.

    N+1 queriesLazy loadingJoinaddSelectleftJoin

  5. The big guestbook

    Exercise 5 · 270 XP · 5 objectives checked by tests

    The guestbook's fame has spread across Middle-earth: Bruna wants a page that gathers all the reviews, for every dish. Pippin wrote it (/guestbook, in LivreDOrController, the guestbook controller), the template is ready, but the page shows every review at once. There are already about fifty of them, and it will soon be unreadable.

    PaginationPaginatorsetFirstResultsetMaxResults#[MapQueryParameter]

  6. 🐉 Boss: the collapsed storeroom

    Exercise 6 · 340 XP · 5 objectives checked by tests

    Pippin took advantage of a quiet night to “tidy up the storeroom”. He added the allergens to the dish pages, and while he was at it, he “simplified two or three things”. The next morning, Bruna finds the tavern upside down:

    DebuggingMigrationsManyToManyN+1 queriesPagination