mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
RDoc: fix wrong model name :inverse_of
with :belongs_to
[ci skip]
There's a typo in ActiveRecord associations RDocs.
Wrong `Taggable` model name, instead of `Tagging` in example of using
option `:inverse_of` with `:belongs_to` association.
Commit where typo was introduced:
91fd651056 (diff-39001423802a8470dba9c931e66e101eR11)
First it appears in `activerecord/CHANGELOG` in example of `:inverse_of`
usage:
```ruby
class Post < ActiveRecord::Base
has_many :taggings
has_many :tags, :through => :taggings
end
class Tagging < ActiveRecord::Base
belongs_to :post
belongs_to :tag, :inverse_of => :tagging # :inverse_of must be set!
end
class Tag < ActiveRecord::Base
has_many :taggings
has_many :posts, :through => :taggings
end
post = Post.first
tag = post.tags.build :name => "ruby"
!> tag.save # will save a Taggable linking to the post
```
The last line should be
```ruby
tag.save # will save a Tagging linking to the post
```
The same typo appears in
`activerecord/lib/active_record/associations.rb`.
The association name is given as `:inverse_of => :taggings`, but class
name is `Taggable`.
```ruby
# @post = Post.first
# @tag = @post.tags.build :name => "ruby"
# @tag.save
#
!> # The last line ought to save the through record (a <tt>Taggable</tt>). This will only work if the
# <tt>:inverse_of</tt> is set:
#
!> # class Taggable < ActiveRecord::Base
# belongs_to :post
!> # belongs_to :tag, :inverse_of => :taggings
# end
```
This PR fixes model name.
This commit is contained in:
parent
70009e3100
commit
4ec818d28c
1 changed files with 3 additions and 3 deletions
|
@ -619,10 +619,10 @@ module ActiveRecord
|
|||
# @tag = @post.tags.build name: "ruby"
|
||||
# @tag.save
|
||||
#
|
||||
# The last line ought to save the through record (a <tt>Taggable</tt>). This will only work if the
|
||||
# The last line ought to save the through record (a <tt>Tagging</tt>). This will only work if the
|
||||
# <tt>:inverse_of</tt> is set:
|
||||
#
|
||||
# class Taggable < ActiveRecord::Base
|
||||
# class Tagging < ActiveRecord::Base
|
||||
# belongs_to :post
|
||||
# belongs_to :tag, inverse_of: :taggings
|
||||
# end
|
||||
|
@ -643,7 +643,7 @@ module ActiveRecord
|
|||
# You can turn off the automatic detection of inverse associations by setting
|
||||
# the <tt>:inverse_of</tt> option to <tt>false</tt> like so:
|
||||
#
|
||||
# class Taggable < ActiveRecord::Base
|
||||
# class Tagging < ActiveRecord::Base
|
||||
# belongs_to :tag, inverse_of: false
|
||||
# end
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue