Skip to content
Browse files

Fixes the fandom's parents

Adds uncategorised media if changed to fandom, removes it if changed from fandom to something else.
  • Loading branch information...
1 parent 57fe81e commit 49d0c78c4f5598bb293b5f45e6b28ee2467593b4 @CristinaRO committed Jul 18, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 app/models/tag.rb
11 app/models/tag.rb
@@ -125,6 +125,17 @@ def update_wrangler(tag)
+ before_save :check_type_changes, :if => :type_changed?
+ def check_type_changes
+ # if the tag was categorised as a Fandom, it had the Uncategorized medium added to it as a parent, and we have to remove it manually
+ if self.type_was == "Fandom" && self.respond_to?(:medias)
+ self.parents = self.parents - self.medias
+ # otherwise, if it has now become a Fandom, it needs the Uncategorized medium added to it manually (the after_save hook on Fandom won't take effect, since it's not a Fandom yet)
+ elsif self.type == "Fandom" && self.parents.empty?
+ self.parents << Media.uncategorized
+ end
+ end
scope :id_only, select("")
scope :canonical, where(:canonical => true)

0 comments on commit 49d0c78

Please sign in to comment.
Something went wrong with that request. Please try again.