You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/source/active_record_querying.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1493,7 +1493,7 @@ Eager Loading Associations
1493
1493
1494
1494
Eager loading is the mechanism for loading the associated records of the objects returned by `Model.find` using as few queries as possible.
1495
1495
1496
-
**N + 1 queries problem**
1496
+
### N + 1 Queries Problem
1497
1497
1498
1498
Consider the following code, which finds 10 books and prints their authors' last_name:
1499
1499
@@ -1507,7 +1507,7 @@ end
1507
1507
1508
1508
This code looks fine at the first sight. But the problem lies within the total number of queries executed. The above code executes 1 (to find 10 books) + 10 (one per each book to load the author) = **11** queries in total.
1509
1509
1510
-
**Solution to N + 1 queries problem**
1510
+
#### Solution to N + 1 Queries Problem
1511
1511
1512
1512
Active Record lets you specify in advance all the associations that are going to be loaded.
0 commit comments