Skip to content

Commit 1c3b8d9

Browse files
kivikakkbyroot
authored andcommitted
Use limit in #sole, not first.
`first` forces an ordering even if we've deliberately removed any orderings on the underlying scope. Given the nature of `#sole`, this change doesn't affect the results, but does allow the user to omit orderings where it would pessimise the query (as we've discovered on a large site).
1 parent d2ffa44 commit 1c3b8d9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

activerecord/lib/active_record/relation/finder_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def take!
141141
#
142142
# Product.where(["price = %?", price]).sole
143143
def sole
144-
found, undesired = first(2)
144+
found, undesired = limit(2)
145145

146146
if found.nil?
147147
raise_record_not_found_exception!

0 commit comments

Comments
 (0)