Merge pull request #40320 from mh-mobile/master

[skip ci]  Fix examples for has_{one,many} :through :source and :source_type
This commit is contained in:
Ryuta Kamizono 2020-11-25 21:45:08 +09:00 committed by GitHub
commit 870f9dfacb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -1351,9 +1351,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
@ -1819,7 +1824,7 @@ class Author < ApplicationRecord
end
class Book < ApplicationRecord
has_one :format, polymorphic: true
belongs_to :format, polymorphic: true
end
class Hardback < ApplicationRecord; end