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 @@valid_encode_columns += ['title', 'description']
11 @@visible_count_options = {:conditions => 'visible > 0'}
14 self.visible = 0 if self.visible.blank?
18 return false unless au
19 self.author_id = au.id
22 def visible? operators
27 def comic_stories_count
28 Story.where(['stories.comic_id = ?', self.id]).count
39 'comics.updated_at desc'
42 def self.mylist_where me
43 ['comics.author_id = ?', me.id]
47 'comics.updated_at desc'
50 def self.himlist_where anybody
51 ['comics.author_id = ? and comics.visible > 0', anybody.id]
54 def self.himlist_order
55 'comics.updated_at desc'
58 def self.list_by_author_where author_id
59 ['comics.author_id = ?', author_id]
62 def self.list_by_author author_id, roles, page = 1, page_size = self.default_page_size
63 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)
67 {:stories => {}, :author => {} }
70 def self.list_json_opt
71 {:include => {:stories => {}, :author => {}} }
75 {:include => {:stories => {}, :author => {}} }
78 def self.show_json_opt
79 {:include => {:stories => {}, :author => {}} }
82 def destroy_with_story
85 self.stories.each do |story|
86 raise ActiveRecord::Rollback unless story.destroy_and_shorten
88 raise ActiveRecord::Rollback unless self.destroy