OSDN Git Service

merge
[pettanr/pettanr.git] / app / models / artist.rb
index 83ecf69..6c97a5e 100644 (file)
@@ -9,16 +9,20 @@ class Artist < Peta::Owner
   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.list_where
+  def self.index_list_where list
     'artists.provider_id is null'
   end
   
@@ -27,15 +31,9 @@ class Artist < Peta::Owner
   end
   
   def self.export(dt = nil)
-    opt = {}
-    cond = if dt
-      ['artists.artists.provider = 0 and artists.updated_at >= ?', dt]
-    else
-      'artists.artists.provider = 0'
-    end
-    opt.merge!({:conditions => cond}) 
-    opt.merge!({:order => 'id'})
-    Artist.find(:all, opt)
+    artists = Artist.where('artists.provider = 0')
+    artists = artists.where(['artists.updated_at >= ?', dt]) if dt
+    artists.order(:id)
   end
   
 end