diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-09-21 21:08:23 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-21 21:08:23 +0900 |
commit | 40eb569377d46ccac82ac89b02fbeac77b1efe7f (patch) | |
tree | 8d4f814923226d13ec632962850dc9789f0cd6fd | |
parent | 87a36ca66507cfcc68df817b6dbd69c036fa3dc4 (diff) | |
parent | f0c161cc05f4964ce3316c14e2dc2b6c445c5cd6 (diff) | |
download | rails-40eb569377d46ccac82ac89b02fbeac77b1efe7f.tar.gz rails-40eb569377d46ccac82ac89b02fbeac77b1efe7f.tar.bz2 rails-40eb569377d46ccac82ac89b02fbeac77b1efe7f.zip |
Merge pull request #33940 from ianfleeton/chapters
Replace line items with chapters [ci skip]
-rw-r--r-- | guides/source/association_basics.md | 26 |
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 ``` |