2 class Comic < Pettanr::Content
3 has_many :stories, :order => 't'
6 validates :title, :presence => true, :length => {:maximum => 100}
7 validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
8 validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
10 @@visible_count_options = {:conditions => 'visible > 0'}
24 def self.valid_encode_columns
25 super + ['title', 'description']
29 self.visible = 0 if self.visible.blank?
32 def overwrite operators
33 return false unless operators.author
34 self.author_id = operators.author.id
37 def visible? operators
42 def comic_stories_count
43 Story.where(['stories.comic_id = ?', self.id]).count
54 'comics.updated_at desc'
57 def self.mylist_where me
58 ['comics.author_id = ?', me.id]
62 'comics.updated_at desc'
65 def self.himlist_where anybody
66 ['comics.author_id = ? and comics.visible > 0', anybody.id]
69 def self.himlist_order
70 'comics.updated_at desc'
73 def self.list_by_author_where author_id
74 ['comics.author_id = ?', author_id]
77 def self.list_by_author author_id, roles, page = 1, page_size = self.default_page_size
78 self.where(self.list_by_author_where(author_id)).includes(self.list_opt).order('comics.updated_at desc').offset((page -1) * page_size).limit(page_size)
82 {:stories => {}, :author => {} }
85 def self.list_json_opt
86 {:include => {:stories => {}, :author => {}} }
90 {:include => {:stories => {}, :author => {}} }
93 def self.show_json_opt
94 {:include => {:stories => {}, :author => {}} }
97 def destroy_with_story
100 self.stories.each do |story|
101 raise ActiveRecord::Rollback unless story.destroy_and_shorten
103 raise ActiveRecord::Rollback unless self.destroy