From 9d547ec8c21c0e2d0598da6fbf3336aae918bfcd Mon Sep 17 00:00:00 2001 From: mh-mobile Date: Fri, 2 Oct 2020 22:03:12 +0900 Subject: [PATCH] Fix examples for has_{one,many} :through :source and :source_type --- guides/source/association_basics.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 8b50ebc0fd..f8eeaca9ef 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -1340,9 +1340,14 @@ The `:source` option specifies the source association name for a `has_one :throu The `:source_type` option specifies the source association type for a `has_one :through` association that proceeds through a polymorphic association. ```ruby +class Author < ApplicationRecord + has_one :book + has_one :hardback, through: :book, source: :format, source_type: "Hardback" + has_one :dust_jacket, through: :hardback +end + class Book < ApplicationRecord - has_one :format, polymorphic: true - has_one :dust_jacket, through: :format, source: :dust_jacket, source_type: "Hardback" + belongs_to :format, polymorphic: true end class Paperback < ApplicationRecord; end @@ -1795,7 +1800,7 @@ class Author < ApplicationRecord end class Book < ApplicationRecord - has_one :format, polymorphic: true + belongs_to :format, polymorphic: true end class Hardback < ApplicationRecord; end