end
def self.max_t binder_id
- self.maximum(:t, :conditions => [self.binder_key + ' = ?', binder_id])
+ self.where([self.binder_key + ' = ?', binder_id]).maximum(:t)
end
def self.find_t binder_id, t
- self.find(:first, :conditions => [self.binder_key + ' = ? and t = ?', binder_id, t])
+ self.where([self.binder_key + ' = ? and t = ?', binder_id, t]).first
end
def self.collect_t binder_id
- r = self.find(:all, :conditions => [self.binder_key + ' = ?', binder_id], :order => 't')
+ r = self.where([self.binder_key + ' = ?', binder_id]).order('t')
r.map {|sp| sp.t}
end
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
res
end
+ # destroy and shorten
def destroy
res = false
self.class.transaction do
- self.class.update_all('t = t - 1',
+ # renumber t
+ 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