Skip to content

Commit afad920

Browse files
authored
Merge pull request rails#55111 from rails/fxn/clarify-through-vs-source
Improve docs through + polymorphic
2 parents 332dc0d + 4c41a58 commit afad920

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

guides/source/association_basics.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,9 @@ end
979979
allowing instances of one model (Physician) to be associated with multiple
980980
instances of another model (Patient) through a third "join" model (Appointment).
981981

982+
We call `Physician.appointments` and `Appointment.patient` the _through_ and
983+
_source_ associations of `Physician.patients`, respectively.
984+
982985
![has_many :through Association
983986
Diagram](images/association_basics/has_many_through.png)
984987

@@ -1013,7 +1016,8 @@ created with `physician_id` and `patient_id` columns, establishing the
10131016
many-to-many relationship between `physicians` and `patients`.
10141017

10151018
INFO: The through association can be any type of association, including other
1016-
through associations, but it cannot be a polymorphic association.
1019+
through associations, but it cannot be [polymorphic](#polymorphic-associations).
1020+
Source associations can be polymorphic as long as you provide a source type.
10171021

10181022
You could also consider using a [composite primary
10191023
key](active_record_composite_primary_keys.html) for the join table in the
@@ -1125,6 +1129,9 @@ end
11251129
This setup allows a `supplier` to directly access its `account_history` through
11261130
its `account`.
11271131

1132+
We call `Supplier.account` and `Account.account_history` the _through_ and
1133+
_source_ associations of `Supplier.account_history`, respectively.
1134+
11281135
![has_one :through Association
11291136
Diagram](images/association_basics/has_one_through.png)
11301137

@@ -1154,7 +1161,8 @@ end
11541161
```
11551162

11561163
INFO: The through association can be any type of association, including other
1157-
through associations, but it cannot be a polymorphic association.
1164+
through associations, but it cannot be [polymorphic](#polymorphic-associations).
1165+
Source associations can be polymorphic as long as you provide a source type.
11581166

11591167
### `has_and_belongs_to_many`
11601168

0 commit comments

Comments
 (0)