OSDN Git Service

fix: any
[pettanr/pettanr.git] / app / models / artist.rb
index 973be0f..6c97a5e 100644 (file)
@@ -1,9 +1,39 @@
-class Artist < ActiveRecord::Base
-  belongs_to :author
+class Artist < Peta::Owner
+  load_manifest
+  belongs_to :user
   has_many :original_pictures
+  has_many :pictures
+  has_many :resource_pictures
+  
+  validates :name, :presence => true, :length => {:maximum => 30}
+  validates :user_id, :numericality => true, :existence => {:both => false}
+  validates :provider_id, :numericality => {:allow_nil => true}
+  
+  scope :find_index, -> do
+    self
+  end
+  
+  def supply_default
+    self.name = 'no name' if self.name.blank?
+    self.user_id = nil
+  end
   
   def self.find_by_author author
-    Artist.find( :first, :conditions => ['author_id = ?', author.id])
+    Artist.where(author_id: author.id).first
+  end
+  
+  def self.index_list_where list
+    'artists.provider_id is null'
+  end
+  
+  def self.show_opt
+    {:include => {:user => {:author => {}}} }
+  end
+  
+  def self.export(dt = nil)
+    artists = Artist.where('artists.provider = 0')
+    artists = artists.where(['artists.updated_at >= ?', dt]) if dt
+    artists.order(:id)
   end
   
 end