OSDN Git Service

temp
[pettanr/pettanr.git] / app / models / artist.rb
1 class Artist < Pettanr::Owner
2   belongs_to :user
3   has_many :original_pictures
4   has_many :pictures
5   has_many :resource_pictures
6   
7   validates :name, :presence => true, :length => {:maximum => 30}
8   validates :user_id, :numericality => true, :existence => {:both => false}
9   validates :provider, :numericality => true
10   
11   @@valid_encode_columns += ['name']
12   @@visible_count_options = {:conditions => ['artists.author_id is not null']}
13   
14   def supply_default
15     self.name = 'no name' if self.name.blank?
16   end
17   
18   def self.find_by_author author
19     Artist.find( :first, :conditions => ['author_id = ?', author.id])
20   end
21   
22   def self.list_where
23     'artists.provider = 0'
24   end
25   
26   def self.list_order
27     'artists.created_at desc'
28   end
29   
30   def self.list_opt
31     {:author => {} }
32   end
33   
34   def self.list_json_opt
35     {:include => {:author => {}} }
36   end
37   
38   def self.show_opt
39     {:include => {:author => {}} }
40   end
41   
42   def self.show_json_opt
43     {:include => {:author => {}} }
44   end
45   
46   def self.export(dt = nil)
47     opt = {}
48     cond = if dt
49       ['artists.artists.provider = 0 and artists.updated_at >= ?', dt]
50     else
51       'artists.artists.provider = 0'
52     end
53     opt.merge!({:conditions => cond}) 
54     opt.merge!({:order => 'id'})
55     Artist.find(:all, opt)
56   end
57   
58 end