OSDN Git Service

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