OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / models / license.rb
index 7bfc26c..f0ebd78 100644 (file)
@@ -14,6 +14,18 @@ class License < Peta::SystemResource
   validates :license_group_settings, :boost => {:boost_name => :license_group}
   validates :credit_picture_settings, :boost => {:boost_name => :credit_picture}
   
+  scope :find_index, -> do
+    self.all
+  end
+  
+  scope :find_by_license_group, -> (license_group_id) do 
+    where(license_group_id: license_group_id)
+  end
+  
+  scope :find_by_system_picture, -> (system_picture_id) do 
+    where(system_picture_id: system_picture_id)
+  end
+  
   def overwrite 
   end
   
@@ -21,20 +33,16 @@ class License < Peta::SystemResource
     self.license_group.caption + '/' + self.caption
   end
   
-  def self.list_where
+  def self.index_list_where list
     ''
   end
   
-  def self.list_order
-    'licenses.name'
-  end
-  
   def self.show_opt
     {:include => {:license_group => {}}}
   end
   
   def self.list_by_name name
-    License.find :all, :conditions => ['licenses.name = ?', name], :order => 'licenses.updated_at desc'
+    License.where(name: name).order(updated_at: :desc)
   end
   
   def self.store name, attr
@@ -42,6 +50,7 @@ class License < Peta::SystemResource
     attr['credit_picture_settings'] = attr['credit_picture_settings'].to_json
     attr['license_group_settings'] = attr['license_group_settings'].to_json
     l = License.modify_object name, attr
+    l.boosts 'post'
     if r == false
       l.errors.add :base, SystemPicture.model_name.human + I18n.t('errors.not_create')
     else
@@ -62,10 +71,9 @@ class License < Peta::SystemResource
   end
   
   def self.export(dt = nil)
-    opt = {}
-    opt.merge!({:conditions => ['updated_at >= ?', dt]}) if dt
-#    opt.merge!({:order => 'name'})
-    License.find(:all, opt)
+    licenses = License.all
+    licenses = licenses.where(['licenses.updated_at >= ?', dt]) if dt
+    licenses.order(:id)
   end
   
 end