mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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:
commit
870f9dfacb
1 changed files with 8 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue