Premier League Predictor: Astro — Chapter 7, Exercise 3 ==================================================== TASK Set up the four-team, three-fixture mini-season from this chapter's own worked example against a real database, call GET /api/seasons/{seasonId}/table, and confirm the returned table matches the worked-example rows exactly — including the Team C vs. Team D tie being broken by goal difference rather than points. SOLUTION Steps to complete the hands-on part: 1. Using the routes from Chapters 2-4, create a season and add four teams to it: Team A, Team B, Team C, Team D. 2. Create a single gameweek and add three fixtures to it via the fixture-entry UI or the API directly: - Team A (home) vs. Team B - Team C (home) vs. Team D - Team A (home) vs. Team D (Team B vs. Team C is deliberately never created — that pairing has not been played.) 3. Enter the real results for all three fixtures via PATCH /api/fixtures/{id}/result: - A vs B -> { "home_score": 3, "away_score": 1 } - C vs D -> { "home_score": 1, "away_score": 1 } - A vs D -> { "home_score": 2, "away_score": 0 } 4. Call GET /api/seasons/{seasonId}/table. Expected response (order matters): [ { "name": "Team A", "played": 2, "won": 2, "drawn": 0, "lost": 0, "goals_for": 5, "goals_against": 1, "goal_difference": 4, "points": 6 }, { "name": "Team C", "played": 1, "won": 0, "drawn": 1, "lost": 0, "goals_for": 1, "goals_against": 1, "goal_difference": 0, "points": 1 }, { "name": "Team D", "played": 2, "won": 0, "drawn": 1, "lost": 1, "goals_for": 1, "goals_against": 3, "goal_difference": -2, "points": 1 }, { "name": "Team B", "played": 1, "won": 0, "drawn": 0, "lost": 1, "goals_for": 1, "goals_against": 3, "goal_difference": -2, "points": 0 } ] Written explanation of the tie: Team C and Team D both finish on exactly 1 point (one draw each, no wins or losses). Points alone can't separate them, so the query's own second ORDER BY key, goal_difference DESC, is what actually decides the order: Team C's goal difference is 0 (1 scored, 1 conceded across its single fixture), while Team D's is -2 (1 scored, 3 conceded across its two fixtures — the draw with Team C plus the 0-2 loss to Team A). Since 0 is greater than -2, Team C is ranked above Team D even though Team D has played more games. Goals scored (the third ORDER BY key) is never even consulted for this particular pair, since the tie is already fully resolved by goal difference before reaching it. WHY THIS WORKS AS AN ANSWER ---------------------------- It completes the real, hands-on setup end to end against a real database and API, reproduces the exact expected response the chapter itself computed by hand, and correctly explains the tie using the query's own real ORDER BY precedence (points, then goal difference, then goals scored) rather than only asserting that "goal difference breaks the tie."