##// END OF EJS Templates
Replaces find(:first) calls....
Jean-Philippe Lang -
r10703:a7023dfa9b8e
parent child
Show More
@@ -177,17 +177,17 module ActiveRecord
177 # Return the next higher item in the list.
177 # Return the next higher item in the list.
178 def higher_item
178 def higher_item
179 return nil unless in_list?
179 return nil unless in_list?
180 acts_as_list_class.find(:first, :conditions =>
180 acts_as_list_class.where(
181 "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}"
181 "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}"
182 )
182 ).first
183 end
183 end
184
184
185 # Return the next lower item in the list.
185 # Return the next lower item in the list.
186 def lower_item
186 def lower_item
187 return nil unless in_list?
187 return nil unless in_list?
188 acts_as_list_class.find(:first, :conditions =>
188 acts_as_list_class.where(
189 "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}"
189 "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}"
190 )
190 ).first
191 end
191 end
192
192
193 # Test if this record is in a list
193 # Test if this record is in a list
@@ -216,12 +216,12 module ActiveRecord #:nodoc:
216 has_many :versions, version_association_options do
216 has_many :versions, version_association_options do
217 # finds earliest version of this record
217 # finds earliest version of this record
218 def earliest
218 def earliest
219 @earliest ||= find(:first, :order => 'version')
219 @earliest ||= order('version').first
220 end
220 end
221
221
222 # find latest version of this record
222 # find latest version of this record
223 def latest
223 def latest
224 @latest ||= find(:first, :order => 'version desc')
224 @latest ||= order('version desc').first
225 end
225 end
226 end
226 end
227 before_save :set_new_version
227 before_save :set_new_version
@@ -413,7 +413,7 module CollectiveIdea #:nodoc:
413
413
414 # on creation, set automatically lft and rgt to the end of the tree
414 # on creation, set automatically lft and rgt to the end of the tree
415 def set_default_left_and_right
415 def set_default_left_and_right
416 highest_right_row = nested_set_scope(:order => "#{quoted_right_column_name} desc").find(:first, :limit => 1,:lock => true )
416 highest_right_row = nested_set_scope(:order => "#{quoted_right_column_name} desc").limit(1).lock(true).first
417 maxright = highest_right_row ? (highest_right_row[right_column_name] || 0) : 0
417 maxright = highest_right_row ? (highest_right_row[right_column_name] || 0) : 0
418 # adds the new node to the right of all existing nodes
418 # adds the new node to the right of all existing nodes
419 self[left_column_name] = maxright + 1
419 self[left_column_name] = maxright + 1
@@ -443,11 +443,11 module CollectiveIdea #:nodoc:
443 in_tenacious_transaction do
443 in_tenacious_transaction do
444 reload_nested_set
444 reload_nested_set
445 # select the rows in the model that extend past the deletion point and apply a lock
445 # select the rows in the model that extend past the deletion point and apply a lock
446 self.class.base_class.find(:all,
446 self.class.base_class.
447 :select => "id",
447 select("id").
448 :conditions => ["#{quoted_left_column_name} >= ?", left],
448 where("#{quoted_left_column_name} >= ?", left).
449 :lock => true
449 lock(true).
450 )
450 all
451
451
452 if acts_as_nested_set_options[:dependent] == :destroy
452 if acts_as_nested_set_options[:dependent] == :destroy
453 descendants.each do |model|
453 descendants.each do |model|
General Comments 0
You need to be logged in to leave comments. Login now