Skip to content

Commit d3c6f48

Browse files
authored
Merge pull request rails#55113 from rails/fxn/fix-has_one-through-docs
Fix docs of has_one :through associations
2 parents afad920 + 3bca919 commit d3c6f48

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

activerecord/lib/active_record/associations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,8 +1415,8 @@ def has_many(name, scope = nil, **options, &extension)
14151415
# [+:through+]
14161416
# Specifies an association through which to perform the query.
14171417
#
1418-
# This can be any other type of association, including other <tt>:through</tt> associations,
1419-
# but it cannot be a polymorphic association. Options for <tt>:class_name</tt>, <tt>:primary_key</tt>,
1418+
# The through association must be a `has_one`, `has_one :through`, or non-polymorphic `belongs_to`.
1419+
# That is, a non-polymorphic singular association. Options for <tt>:class_name</tt>, <tt>:primary_key</tt>,
14201420
# and <tt>:foreign_key</tt> are ignored, as the association uses the source reflection. You can only
14211421
# use a <tt>:through</tt> query through a #has_one or #belongs_to association on the join model.
14221422
#

guides/source/association_basics.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,10 @@ class CreateAccountHistories < ActiveRecord::Migration[8.1]
11601160
end
11611161
```
11621162

1163-
INFO: The through association can be any type of association, including other
1164-
through associations, but it cannot be [polymorphic](#polymorphic-associations).
1165-
Source associations can be polymorphic as long as you provide a source type.
1163+
INFO: The through association must be a `has_one`, `has_one :through`, or
1164+
non-polymorphic `belongs_to`. That is, a non-polymorphic singular association.
1165+
On the other hand, source associations can be polymorphic as long as you provide
1166+
a source type.
11661167

11671168
### `has_and_belongs_to_many`
11681169

0 commit comments

Comments
 (0)