OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / story.rb
index 7f646f8..7c3354d 100644 (file)
@@ -1,3 +1,42 @@
 #ストーリー
-class Story < ActiveRecord::Base
+class Story < Peta::Binder
+  load_manifest
+  has_many :comic_stories
+  has_many :story_sheets
+  belongs_to :author
+  
+  validates :title, :presence => true, :length => {:maximum => 100}
+  validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
+  validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
+  
+  def supply_default
+    self.visible = 0 if self.visible.blank?
+    self.author_id = nil
+  end
+  
+  def overwrite operators
+    return false unless operators.author
+    self.author_id = operators.author.id
+    super()
+  end
+  
+  def visible? operators
+    case super
+    when nil # super return
+      return true
+    when false
+      return false
+    else
+      self.visible > 0
+    end
+  end
+  
+  def self.public_list_where list
+    'stories.visible > 0'
+  end
+  
+  def self.show_opt
+    {:include => {:story_sheets => {:sheet => {}}, :author => {}}}
+  end
+  
 end