OSDN Git Service

t#30328:create op import ...and pull
[pettanr/pettanr.git] / app / models / story.rb
index 3a6cbe0..b4c609c 100644 (file)
@@ -4,9 +4,9 @@ class Story < ActiveRecord::Base
   belongs_to :panel
   belongs_to :comic
   
-  validates :comic_id, :presence => true, :numericality => true, :existence => true
-  validates :panel_id, :presence => true, :numericality => true, :existence => true
-  validates :author_id, :presence => true, :numericality => true, :existence => true
+  validates :comic_id, :presence => true, :numericality => true, :existence => {:both => false}
+  validates :panel_id, :presence => true, :numericality => true, :existence => {:both => false}
+  validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
   def supply_default
@@ -182,7 +182,7 @@ class Story < ActiveRecord::Base
   def self.licensed_pictures stories
     r = {}
     stories.each do |story|
-      r.merge! story.panel.licensed_pictures
+      r.merge!(story.panel.licensed_pictures) if story.panel
     end
     r
   end
@@ -280,10 +280,13 @@ class Story < ActiveRecord::Base
   end
   
   def destroy_and_shorten
+    res = false
     Story.transaction do
       Story.update_all('t = t - 1', ['comic_id = ? and (t > ?)', self.comic_id, self.t])
       raise ActiveRecord::Rollback unless self.destroy
+      res = true
     end
+    res
   end