diff options
author | Thiago Pinto <tapgyn@gmail.com> | 2013-06-08 13:35:47 -0400 |
---|---|---|
committer | Thiago Pinto <tapgyn@gmail.com> | 2013-06-08 13:35:47 -0400 |
commit | b8640d47907876d43335628fea40da03df0e84cd (patch) | |
tree | 15dd97cb59a64b0fb474855826d0095036fc272f /activerecord | |
parent | 04417f3eb5decfe2df77f227e679c8360e7e6e97 (diff) | |
download | rails-b8640d47907876d43335628fea40da03df0e84cd.tar.gz rails-b8640d47907876d43335628fea40da03df0e84cd.tar.bz2 rails-b8640d47907876d43335628fea40da03df0e84cd.zip |
explaining ActiveRecord#first in rails 3 and 4
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index ba222aac93..86976077d6 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -79,6 +79,19 @@ module ActiveRecord # Person.where(["user_name = :u", { u: user_name }]).first # Person.order("created_on DESC").offset(5).first # Person.first(3) # returns the first three objects fetched by SELECT * FROM people LIMIT 3 + # + # ==== Rails 3 + # + # Person.first # SELECT "users".* FROM "users" LIMIT 1 + # + # NOTE: Rails 3 may not +order+ this query by be the primary key. + # The order will depend on the database implementation. + # In order to ensure that behavior use <tt>User.order(:id).first</tt> instead. + # + # ==== Rails 4 + # + # Person.first # SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 + # def first(limit = nil) if limit if order_values.empty? && primary_key |