2 class Story < Peta::Binder
4 has_many :comic_stories
6 has_many :sheets, :through => :story_sheets
7 has_many :play_story_sheets, :class_name => 'StorySheet', :order => 't'
8 has_many :play_sheets, :source => 'Sheet', :through => :play_story_sheets
11 validates :title, :presence => true, :length => {:maximum => 100}
12 validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
13 validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
16 self.visible = 0 if self.visible.blank?
19 def overwrite operators
20 return false unless operators.author
21 self.author_id = operators.author.id
25 def visible? operators
27 when nil # super return
36 def story_sheets_count
37 StorySheet.where(['story_sheets.story_id = ?', self.id]).count
40 def self.public_list_where
45 {:comic_stories => {:comic => {}}, :author => {} }
48 def self.list_json_opt
49 {:include => {:comic_stories => {:include => {:comic => {}}}, :author => {}}}
53 {:include => {:comic_stories => {:comic => {}}, :author => {}}}
56 def self.show_json_opt
57 {:include => {:comic_stories => {:include => {:comic => {}}}, :author => {}}}