OSDN Git Service

rails upgrade to 4
[pettanr/pettanr.git] / app / models / artist.rb
index 72fb2b1..77dbf1f 100644 (file)
@@ -1,4 +1,5 @@
-class Artist < Pettanr::Owner
+class Artist < Peta::Owner
+  load_manifest
   belongs_to :user
   has_many :original_pictures
   has_many :pictures
@@ -6,53 +7,29 @@ class Artist < Pettanr::Owner
   
   validates :name, :presence => true, :length => {:maximum => 30}
   validates :user_id, :numericality => true, :existence => {:both => false}
-  validates :provider, :numericality => true
-  
-  @@valid_encode_columns += ['name']
-  @@visible_count_options = {:conditions => ['artists.author_id is not null']}
+  validates :provider_id, :numericality => {:allow_nil => true}
   
   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])
-  end
-  
-  def self.list_where
-    'artists.provider = 0'
-  end
-  
-  def self.list_order
-    'artists.created_at desc'
+    Artist.where(author_id: author.id).first
   end
   
-  def self.list_opt
-    {:author => {} }
-  end
-  
-  def self.list_json_opt
-    {:include => {:author => {}} }
+  def self.index_list_where list
+    'artists.provider_id is null'
   end
   
   def self.show_opt
-    {:include => {:author => {}} }
-  end
-  
-  def self.show_json_opt
-    {:include => {:author => {}} }
+    {:include => {:user => {:author => {}}} }
   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