Skip to content

Commit ad858b9

Browse files
committed
Update docs re :class_name and polymorphic associations
1 parent f6481c4 commit ad858b9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

activerecord/lib/active_record/associations.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,9 @@ def has_one(name, scope = nil, **options)
15761576
# [+:class_name+]
15771577
# Specify the class name of the association. Use it only if that name can't be inferred
15781578
# from the association name. So <tt>belongs_to :author</tt> will by default be linked to the Author class, but
1579-
# if the real class name is Person, you'll have to specify it with this option.
1579+
# if the real class name is Person, you'll have to specify it with this option. +:class_name+
1580+
# is not supported in polymorphic associations, since in that case the class name of the
1581+
# associated record is stored in the type column.
15801582
# [+:foreign_key+]
15811583
# Specify the foreign key used for the association. By default this is guessed to be the name
15821584
# of the association with an "_id" suffix. So a class that defines a <tt>belongs_to :person</tt>

guides/source/association_basics.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,9 @@ class Book < ApplicationRecord
25792579
end
25802580
```
25812581

2582+
This option is no supported in polymorphic associations, since in that case the
2583+
class name of the associated record is stored in the type column.
2584+
25822585
#### `:dependent`
25832586

25842587
Controls what happens to the associated object when its owner is destroyed:

0 commit comments

Comments
 (0)