OSDN Git Service

classname rename to module_name
[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     self.user_id = nil
15   end
16   
17   def self.find_by_author author
18     Artist.find( :first, :conditions => ['author_id = ?', author.id])
19   end
20   
21   def self.list_where
22     'artists.provider_id is null'
23   end
24   
25   def self.show_opt
26     {:include => {:user => {:author => {}}} }
27   end
28   
29   def self.export(dt = nil)
30     opt = {}
31     cond = if dt
32       ['artists.artists.provider = 0 and artists.updated_at >= ?', dt]
33     else
34       'artists.artists.provider = 0'
35     end
36     opt.merge!({:conditions => cond}) 
37     opt.merge!({:order => 'id'})
38     Artist.find(:all, opt)
39   end
40   
41 end