1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use join_foreign_key rather than self constructed key name

This commit is contained in:
Ryuta Kamizono 2020-07-03 18:58:44 +09:00
parent 19d8578361
commit 587c5a8361

View file

@ -112,12 +112,12 @@ module ActiveRecord
case association.macro
when :belongs_to
# Do not replace association name with association foreign key if they are named the same
fk_name = (association.options[:foreign_key] || "#{association.name}_id").to_s
fk_name = association.join_foreign_key
if association.name.to_s != fk_name && value = @row.delete(association.name.to_s)
if association.polymorphic? && value.sub!(/\s*\(([^\)]*)\)\s*$/, "")
# support polymorphic belongs_to as "label (Type)"
@row[association.foreign_type] = $1
@row[association.join_foreign_type] = $1
end
fk_type = reflection_class.type_for_attribute(fk_name).type