OSDN Git Service

add: social button
[pettanr/pettanr.git] / lib / peta / leaf.rb
index a736a71..26cd8a6 100644 (file)
@@ -117,25 +117,19 @@ module Peta
     end
     
     def insert_shift
-      self.class.update_all('t = t + 1', 
-        [self.binder_key + ' = ? and t >= ?', self.binder_id, self.t]
-      )
+      self.class.where([self.binder_key + ' = ? and t >= ?', self.binder_id, self.t]).update_all('t = t + 1')
     end
     
     def lesser_shift old_t
       self.t = 0 if self.t < 0
-      self.class.update_all('t = t + 1', 
-        [self.binder_key + ' = ? and (t >= ? and t < ?)', self.binder_id, self.t, old_t]
-      )
+      self.class.where([self.binder_key + ' = ? and (t >= ? and t < ?)', self.binder_id, self.t, old_t]).update_all('t = t + 1')
     end
     
     def higher_shift old_t
       nf = self.class.find_t(self.binder_id, self.t)
       max_t = self.class.max_t(self.binder_id).to_i
       self.t = max_t if self.t > max_t
-      self.class.update_all('t = t - 1', 
-        [self.binder_key + ' = ? and (t > ? and t <= ?)', self.binder_id, old_t, self.t]
-      )
+      self.class.where([self.binder_key + ' = ? and (t > ? and t <= ?)', self.binder_id, old_t, self.t]).update_all('t = t - 1')
     end
     
     def update_shift old_t
@@ -187,9 +181,9 @@ module Peta
       res = false
       self.class.transaction do
         # renumber t
-        self.class.update_all('t = t - 1', 
+        self.class.where(
           [self.binder_key + ' = ? and (t > ?)', self.binder_id, self.t]
-        )
+        ).update_all('t = t - 1')
         res = super
         raise ActiveRecord::Rollback unless res
       end