OSDN Git Service

t#30328:create op import ...and pull
[pettanr/pettanr.git] / app / models / user.rb
index 90958af..5c80960 100644 (file)
@@ -19,4 +19,26 @@ class User < ActiveRecord::Base
     self.save
   end
   
+  def destroy
+    res = false
+    User.transaction do
+      self.author.comics.each do |comic|
+        raise ActiveRecord::Rollback unless comic.destroy_with_story
+      end
+      self.author.panels.each do |panel|
+        raise ActiveRecord::Rollback unless panel.destroy_with_elements
+      end
+      if self.author.artist
+        self.author.artist.original_pictures.each do |original_picture|
+          raise ActiveRecord::Rollback unless original_picture.destroy_with_resource_picture
+        end
+        raise ActiveRecord::Rollback unless self.author.artist.destroy
+      end
+      raise ActiveRecord::Rollback unless self.author.destroy
+      raise ActiveRecord::Rollback unless super
+      res = true
+    end
+    res
+  end
+  
 end