make mapping polymorphism migration handle mapping problems

This commit is contained in:
Devin Howard 2016-01-06 10:23:01 +08:00
parent 21aba2fe5e
commit 75d9339010

View file

@ -15,12 +15,16 @@ class MappingPolymorphism < ActiveRecord::Migration
end
unless mapping.synapse_id.nil?
mapping.mappable = Synapse.find(mapping.synapse_id)
mapping.mappable = Synapse.find_by(id: mapping.synapse_id)
else
next if mapping.topic_id == 0
mapping.mappable = Topic.find(mapping.topic_id)
mapping.mappable = Topic.find_by(id: mapping.topic_id)
end
if mapping.mappable.nil?
mapping.delete
else
mapping.save
end
mapping.save
end
end