Tagging
有一个 [:tag_id, :taggable_id, :taggable_type] 的 unique 制约,下面的代码有什么办法可以优化一下么?
def merge_taggings(remained_tag_id, delete_tag_ids)
Tagging.where(tag_id: delete_tag_ids).each do |tagging|
if Tagging.exists?(tagging.taggable_id, tagging.taggable_type, tag_id: remained_tag_id)
tagging.delete
else
tagging.update(tag_id: remained_tag_id)
end
end
end