Merge pull request #51940 from p8/guides/fix-eager-load-examples

Fix query result of eager_load example in the guides. [ci-skip]
This commit is contained in:
Petrik de Heus 2024-07-13 21:23:34 +02:00 committed by GitHub
commit 4835c94d8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1744,13 +1744,12 @@ books.each do |book|
end
```
The above code will execute just **2** queries, as opposed to the **11** queries from the original case:
The above code will execute just **1** query, as opposed to the **11** queries from the original case:
```sql
SELECT DISTINCT books.id FROM books LEFT OUTER JOIN authors ON authors.id = books.author_id LIMIT 10
SELECT books.id AS t0_r0, books.last_name AS t0_r1, ...
FROM books LEFT OUTER JOIN authors ON authors.id = books.author_id
WHERE books.id IN (1,2,3,4,5,6,7,8,9,10)
SELECT "books"."id" AS t0_r0, "books"."title" AS t0_r1, ... FROM "books"
LEFT OUTER JOIN "authors" ON "authors"."id" = "books"."author_id"
LIMIT 10
```
NOTE: The `eager_load` method uses an array, hash, or a nested hash of array/hash in the same way as the `includes` method to load any number of associations with a single `Model.find` call. Also, like the `includes` method, you can specify conditions for eager loaded associations.