Raises ActiveRecord::AssociationTypeMismatch
unless record is of the kind of the class of the associated
objects. Meant to be used as a sanity check when you are about to assign an
associated record.
# File activerecord/lib/active_record/associations/association.rb, line 240
def raise_on_type_mismatch!(record)
unless record.is_a?(reflection.klass)
fresh_class = reflection.class_name.safe_constantize
unless fresh_class && record.is_a?(fresh_class)
message = "#{reflection.class_name}(##{reflection.klass.object_id}) expected, " "got #{record.inspect} which is an instance of #{record.class}(##{record.class.object_id})"
raise ActiveRecord::AssociationTypeMismatch, message
end
end
end