aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorMarcelo Silveira <marcelo@mhfs.com.br>2012-05-05 12:07:20 -0300
committerMarcelo Silveira <marcelo@mhfs.com.br>2012-05-05 12:10:52 -0300
commit56bf1f74557e68455552eeac1bc975cf9ba57766 (patch)
tree5f3f5013aba1129a035b074a49e17fd59f3fe25b /activerecord/lib/active_record
parentacb39848ae4cfe1d22cd8a83c5db636d80c22b47 (diff)
downloadrails-56bf1f74557e68455552eeac1bc975cf9ba57766.tar.gz
rails-56bf1f74557e68455552eeac1bc975cf9ba57766.tar.bz2
rails-56bf1f74557e68455552eeac1bc975cf9ba57766.zip
Use `take` instead of `first` to avoid unwanted implicit ordering (fixes #6147)
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index a78e3d08e4..cc716bbfd1 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -51,13 +51,13 @@ module ActiveRecord
# Post.find_by "published_at < ?", 2.weeks.ago
#
def find_by(*args)
- where(*args).first
+ where(*args).take
end
# Like <tt>find_by</tt>, except that if no record is found, raises
# an <tt>ActiveRecord::RecordNotFound</tt> error.
def find_by!(*args)
- where(*args).first!
+ where(*args).take!
end
# Gives a record (or N records if a parameter is supplied) without any implied
@@ -269,7 +269,7 @@ module ActiveRecord
substitute = connection.substitute_at(column, bind_values.length)
relation = where(table[primary_key].eq(substitute))
relation.bind_values += [[column, id]]
- record = relation.first
+ record = relation.take
unless record
conditions = arel.where_sql
@@ -309,7 +309,7 @@ module ActiveRecord
def find_take
if loaded?
- @records.take(1).first
+ @records.first
else
@take ||= limit(1).to_a.first
end