OSDN Git Service

fix: any
[pettanr/pettanr.git] / app / models / picture.rb
index 3e0cb1d..d147a1f 100644 (file)
@@ -28,6 +28,14 @@ class Picture < Peta::Content
     find_index.where(artist_id: artist_id)
   end
   
+  scope :find_by_md5, -> (md5) do 
+    find_index.where(md5: md5).order(updated_at: :desc)
+  end
+  
+  scope :find_by_md5_without_original_picture, -> (md5, original_picture_id) do 
+    self.find_by_md5(md5).where.not(original_picture_id: original_picture_id).order(updated_at: :desc)
+  end
+  
   scope :find_by_original_picture, -> (original_picture_id) do 
     find_index.where(original_picture_id: original_picture_id)
   end
@@ -130,21 +138,8 @@ class Picture < Peta::Content
     self.license_extend.reverse < 0 ? [''] : ['', 'v', 'h', 'vh']
   end
   
-  def self.find_by_md5 md5
-    r = Picture.where(md5: md5).order(updated_at: :desc)
-  end
-  
-  def self.list_by_md5 md5, opid = nil
-    cond = if opid.blank?
-      {md5: md5}
-    else
-      ['md5 = :md5 and original_picture_id <> :opid', {md5: md5, opid: opid}]
-    end
-    r = Picture.where(cond).order(updated_at: :desc)
-  end
-  
   def self.exist_by_md5 md5, opid
-    Picture.list_by_md5(md5, opid).empty? ? false : true
+    Picture.find_by_md5(md5, opid).empty? ? false : true
   end
   
   def self.list_by_original_picture_where original_picture_id