X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fmodels%2Fartist.rb;h=6c97a5e60d597245f404dd4b984764b374faea0e;hp=d30529247b451d7d32318dc9147291d55e3449af;hb=d7c8065be895b67dc453b0e11ad0f259f1ca6706;hpb=f20e087a523621b9e3efc6778509267fc25e5a70 diff --git a/app/models/artist.rb b/app/models/artist.rb index d3052924..6c97a5e6 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -7,7 +7,11 @@ class Artist < Peta::Owner validates :name, :presence => true, :length => {:maximum => 30} validates :user_id, :numericality => true, :existence => {:both => false} - #validates :provider, :numericality => {:allow_nil => true} + validates :provider_id, :numericality => {:allow_nil => true} + + scope :find_index, -> do + self + end def supply_default self.name = 'no name' if self.name.blank? @@ -15,11 +19,11 @@ class Artist < Peta::Owner 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 - 'artists.provider is null' + def self.index_list_where list + 'artists.provider_id is null' end def self.show_opt @@ -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