OSDN Git Service

fix: fetch fail
[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   scope :find_index, -> do
13     self
14   end
15   
16   def supply_default
17     self.name = 'no name' if self.name.blank?
18     self.user_id = nil
19   end
20   
21   def self.find_by_author author
22     Artist.where(author_id: author.id).first
23   end
24   
25   def self.index_list_where list
26     'artists.provider_id is null'
27   end
28   
29   def self.show_opt
30     {:include => {:user => {:author => {}}} }
31   end
32   
33   def self.export(dt = nil)
34     artists = Artist.where('artists.provider = 0')
35     artists = artists.where(['artists.updated_at >= ?', dt]) if dt
36     artists.order(:id)
37   end
38   
39 end