Skip to content

Commit d293276

Browse files
authored
Merge pull request rails#53389 from p8/activerecord/inverse-of-links
Link to Assocation sections on the same page [ci-skip]
2 parents fecd069 + 2929df8 commit d293276

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

activerecord/lib/active_record/associations.rb

+28-16
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def association_instance_set(name, association)
559559
# @group.avatars << Avatar.new # this would work if User belonged_to Avatar rather than the other way around
560560
# @group.avatars.delete(@group.avatars.last) # so would this
561561
#
562-
# == Setting Inverses
562+
# === Setting Inverses
563563
#
564564
# If you are using a #belongs_to on the join model, it is a good idea to set the
565565
# <tt>:inverse_of</tt> option on the #belongs_to, which will mean that the following example
@@ -1221,8 +1221,11 @@ module ClassMethods
12211221
# If you are going to modify the association (rather than just read from it), then it is
12221222
# a good idea to set the <tt>:inverse_of</tt> option on the source association on the
12231223
# join model. This allows associated records to be built which will automatically create
1224-
# the appropriate join model records when they are saved. (See the 'Association Join Models'
1225-
# and 'Setting Inverses' sections above.)
1224+
# the appropriate join model records when they are saved. See
1225+
# {Association Join Models}[rdoc-ref:Associations::ClassMethods@Association+Join+Models]
1226+
# and {Setting Inverses}[rdoc-ref:Associations::ClassMethods@Setting+Inverses] for
1227+
# more detail.
1228+
12261229
# [+:disable_joins+]
12271230
# Specifies whether joins should be skipped for an association. If set to true, two or more queries
12281231
# will be generated. Note that in some cases, if order or limit is applied, it will be done in-memory
@@ -1251,7 +1254,8 @@ module ClassMethods
12511254
# [+:inverse_of+]
12521255
# Specifies the name of the #belongs_to association on the associated object
12531256
# that is the inverse of this #has_many association.
1254-
# See ActiveRecord::Associations::ClassMethods's overview on Bi-directional associations for more detail.
1257+
# See {Bi-directional associations}[rdoc-ref:Associations::ClassMethods@Bi-directional+associations]
1258+
# for more detail.
12551259
# [+:extend+]
12561260
# Specifies a module or array of modules that will be extended into the association object returned.
12571261
# Useful for defining methods on associations, especially when they should be shared between multiple
@@ -1300,10 +1304,12 @@ def has_many(name, scope = nil, **options, &extension)
13001304
Reflection.add_reflection self, name, reflection
13011305
end
13021306

1303-
# Specifies a one-to-one association with another class. This method should only be used
1304-
# if the other class contains the foreign key. If the current class contains the foreign key,
1305-
# then you should use #belongs_to instead. See also ActiveRecord::Associations::ClassMethods's overview
1306-
# on when to use #has_one and when to use #belongs_to.
1307+
# Specifies a one-to-one association with another class. This method
1308+
# should only be used if the other class contains the foreign key. If
1309+
# the current class contains the foreign key, then you should use
1310+
# #belongs_to instead. See {Is it a belongs_to or has_one
1311+
# association?}[rdoc-ref:Associations::ClassMethods@Is+it+a+-23belongs_to+or+-23has_one+association-3F]
1312+
# for more detail on when to use #has_one and when to use #belongs_to.
13071313
#
13081314
# The following methods for retrieval and query of a single associated object will be added:
13091315
#
@@ -1418,8 +1424,10 @@ def has_many(name, scope = nil, **options, &extension)
14181424
# If you are going to modify the association (rather than just read from it), then it is
14191425
# a good idea to set the <tt>:inverse_of</tt> option on the source association on the
14201426
# join model. This allows associated records to be built which will automatically create
1421-
# the appropriate join model records when they are saved. (See the 'Association Join Models'
1422-
# and 'Setting Inverses' sections above.)
1427+
# the appropriate join model records when they are saved. See
1428+
# {Association Join Models}[rdoc-ref:Associations::ClassMethods@Association+Join+Models]
1429+
# and {Setting Inverses}[rdoc-ref:Associations::ClassMethods@Setting+Inverses] for
1430+
# more detail.
14231431
# [+:disable_joins+]
14241432
# Specifies whether joins should be skipped for an association. If set to true, two or more queries
14251433
# will be generated. Note that in some cases, if order or limit is applied, it will be done in-memory
@@ -1457,7 +1465,8 @@ def has_many(name, scope = nil, **options, &extension)
14571465
# [+:inverse_of+]
14581466
# Specifies the name of the #belongs_to association on the associated object
14591467
# that is the inverse of this #has_one association.
1460-
# See ActiveRecord::Associations::ClassMethods's overview on Bi-directional associations for more detail.
1468+
# See {Bi-directional associations}[rdoc-ref:Associations::ClassMethods@Bi-directional+associations]
1469+
# for more detail.
14611470
# [+:required+]
14621471
# When set to +true+, the association will also have its presence validated.
14631472
# This will validate the association itself, not the id. You can use
@@ -1491,10 +1500,12 @@ def has_one(name, scope = nil, **options)
14911500
Reflection.add_reflection self, name, reflection
14921501
end
14931502

1494-
# Specifies a one-to-one association with another class. This method should only be used
1495-
# if this class contains the foreign key. If the other class contains the foreign key,
1496-
# then you should use #has_one instead. See also ActiveRecord::Associations::ClassMethods's overview
1497-
# on when to use #has_one and when to use #belongs_to.
1503+
# Specifies a one-to-one association with another class. This method
1504+
# should only be used if this class contains the foreign key. If the
1505+
# other class contains the foreign key, then you should use #has_one
1506+
# instead. See {Is it a belongs_to or has_one
1507+
# association?}[rdoc-ref:Associations::ClassMethods@Is+it+a+-23belongs_to+or+-23has_one+association-3F]
1508+
# for more detail on when to use #has_one and when to use #belongs_to.
14981509
#
14991510
# Methods will be added for retrieval and query for a single associated object, for which
15001511
# this object holds an id:
@@ -1636,7 +1647,8 @@ def has_one(name, scope = nil, **options)
16361647
# [+:inverse_of+]
16371648
# Specifies the name of the #has_one or #has_many association on the associated
16381649
# object that is the inverse of this #belongs_to association.
1639-
# See ActiveRecord::Associations::ClassMethods's overview on Bi-directional associations for more detail.
1650+
# See {Bi-directional associations}[rdoc-ref:Associations::ClassMethods@Bi-directional+associations]
1651+
# for more detail.
16401652
# [+:optional+]
16411653
# When set to +true+, the association will not have its presence validated.
16421654
# [+:required+]

0 commit comments

Comments
 (0)