Permalink
Browse files

find_one uses find_every.first instead of find_initial since its prim…

…ary key constraint obviates find_initial's :limit => 1. References #5635.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4578 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
jeremy committed Jul 7, 2006
1 parent 69d8ca4 commit 230c5a060ba7fe3ac2f78f5975debd04e85167cb
Showing with 4 additions and 1 deletion.
  1. +4 −1 activerecord/lib/active_record/base.rb
@@ -981,7 +981,10 @@ def find_one(id, options)
conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions]
options.update :conditions => "#{table_name}.#{primary_key} = #{quote(id,columns_hash[primary_key])}#{conditions}"
- if result = find_initial(options)
+ # Use find_every(options).first since the primary key condition
+ # already ensures we have a single record. Using find_initial adds
+ # a superfluous :limit => 1.
+ if result = find_every(options).first
result
else
raise RecordNotFound, "Couldn't find #{name} with ID=#{id}#{conditions}"

0 comments on commit 230c5a0

Please sign in to comment.