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