Fix missing tagged_ids in some taggable objects and add a rake task for it
This commit is contained in:
parent
ceac2b842c
commit
3467868607
|
@ -43,6 +43,7 @@ module OrbitTag
|
|||
def tags=(tag_ids)
|
||||
ids = [tag_ids].flatten
|
||||
tag_ids.delete('')
|
||||
self.tagged_ids = tag_ids
|
||||
ids = self.taggings.blank? ? [] : self.taggings.map{|t| t.tag.id}
|
||||
tag_ids.each do |tag_id|
|
||||
unless ids.include? tag_id
|
||||
|
@ -58,9 +59,6 @@ module OrbitTag
|
|||
|
||||
def tag_ids=(ids)
|
||||
self.tags = ids
|
||||
ids = [ids].flatten
|
||||
ids.delete('')
|
||||
self.tagged_ids = ids
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -310,4 +310,16 @@ namespace :migrate do
|
|||
Rake::Task["web_link_url:web_link_url_i18n"].execute
|
||||
end
|
||||
|
||||
task :fix_tagged_ids => :environment do
|
||||
Tag.all.each do |tag|
|
||||
tag.taggings.each do |tagging|
|
||||
tagged_ids = tagging.taggable.tagged_ids
|
||||
unless tagged_ids.include?(tag.id.to_s)
|
||||
tagged_ids << tag.id.to_s
|
||||
tagging.taggable.update_attribute(:tagged_ids, tagged_ids)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue