# this fixes polymorphic assignment relationships so the _type field is set when you assign an object to the association. module ActiveRecord module Associations class BelongsToPolymorphicAssociation < AssociationProxy #:nodoc: def replace_with_assignment_anyways(record) replace_without_assignment_anyways(record) record && @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s end alias_method_chain :replace, :assignment_anyways end end end