Exercise 2: Dynamic vs. Fixed Eager-Loading Strategies — Possible Solution ==================================================================== WHAT ELOQUENT'S with() AND DJANGO'S select_related ALWAYS DO ------------------------------ Per this chapter, Eloquent's with() always runs exactly two separate, batched queries - one for the base rows, and one WHERE IN query covering everything related to them. Django's select_related always runs a single SQL JOIN - one query, with no alternative strategy. In both cases, the strategy is a fixed property of the method itself, chosen the same way every time it's called. WHAT MAKES includes() DIFFERENT ------------------------------ Per this chapter, ActiveRecord's includes() behaves like Eloquent's own two-query strategy by default, but it isn't locked into that behavior - if the associated table is also referenced inside a where clause (via .references()), Rails automatically switches to a single LEFT OUTER JOIN instead. Which strategy actually runs depends on how the query itself is used, not on a fixed choice baked into the includes() method the way it is for the other two. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains that with() and select_related each always use one fixed strategy, and correctly explains that includes() dynamically switches between the two-query and single-JOIN strategies depending on whether the association is referenced in a filter - the genuine mechanical difference between the three.