aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorIan Fleeton <ianfleeton@gmail.com>2018-09-21 12:38:30 +0100
committerIan Fleeton <ianfleeton@gmail.com>2018-09-21 12:40:16 +0100
commitf0c161cc05f4964ce3316c14e2dc2b6c445c5cd6 (patch)
tree8d4f814923226d13ec632962850dc9789f0cd6fd /guides
parent87a36ca66507cfcc68df817b6dbd69c036fa3dc4 (diff)
downloadrails-f0c161cc05f4964ce3316c14e2dc2b6c445c5cd6.tar.gz
rails-f0c161cc05f4964ce3316c14e2dc2b6c445c5cd6.tar.bz2
rails-f0c161cc05f4964ce3316c14e2dc2b6c445c5cd6.zip
Replace line items with chapters [ci skip]
Line items are a holdover from when orders were used in the examples instead of books.
Diffstat (limited to 'guides')
-rw-r--r--guides/source/association_basics.md26
1 files changed, 13 insertions, 13 deletions
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md
index 008c7345e9..a2231c55d7 100644
--- a/guides/source/association_basics.md
+++ b/guides/source/association_basics.md
@@ -1075,13 +1075,13 @@ end
You can use the `includes` method to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:
```ruby
-class LineItem < ApplicationRecord
+class Chapter < ApplicationRecord
belongs_to :book
end
class Book < ApplicationRecord
belongs_to :author
- has_many :line_items
+ has_many :chapters
end
class Author < ApplicationRecord
@@ -1089,16 +1089,16 @@ class Author < ApplicationRecord
end
```
-If you frequently retrieve authors directly from line items (`@line_item.book.author`), then you can make your code somewhat more efficient by including authors in the association from line items to books:
+If you frequently retrieve authors directly from chapters (`@chapter.book.author`), then you can make your code somewhat more efficient by including authors in the association from chapters to books:
```ruby
-class LineItem < ApplicationRecord
+class Chapter < ApplicationRecord
belongs_to :book, -> { includes :author }
end
class Book < ApplicationRecord
belongs_to :author
- has_many :line_items
+ has_many :chapters
end
class Author < ApplicationRecord
@@ -1779,8 +1779,8 @@ The `group` method supplies an attribute name to group the result set by, using
```ruby
class Author < ApplicationRecord
- has_many :line_items, -> { group 'books.id' },
- through: :books
+ has_many :chapters, -> { group 'books.id' },
+ through: :books
end
```
@@ -1795,27 +1795,27 @@ end
class Book < ApplicationRecord
belongs_to :author
- has_many :line_items
+ has_many :chapters
end
-class LineItem < ApplicationRecord
+class Chapter < ApplicationRecord
belongs_to :book
end
```
-If you frequently retrieve line items directly from authors (`@author.books.line_items`), then you can make your code somewhat more efficient by including line items in the association from authors to books:
+If you frequently retrieve chapters directly from authors (`@author.books.chapters`), then you can make your code somewhat more efficient by including chapters in the association from authors to books:
```ruby
class Author < ApplicationRecord
- has_many :books, -> { includes :line_items }
+ has_many :books, -> { includes :chapters }
end
class Book < ApplicationRecord
belongs_to :author
- has_many :line_items
+ has_many :chapters
end
-class LineItem < ApplicationRecord
+class Chapter < ApplicationRecord
belongs_to :book
end
```