aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAlvaro Pereyra <alvaro@xendacentral.com>2012-05-28 02:51:47 -0500
committerAlvaro Pereyra <alvaro@xendacentral.com>2012-05-28 02:52:11 -0500
commit19de3d8d7fe623b8c9d67676f8113296ebdbb640 (patch)
tree79e0d95775ac9ffefb184ee5a34b63f94800e3f2 /activerecord/lib
parent72973a30704894c808836d80a001208c1af39e7c (diff)
downloadrails-19de3d8d7fe623b8c9d67676f8113296ebdbb640.tar.gz
rails-19de3d8d7fe623b8c9d67676f8113296ebdbb640.tar.bz2
rails-19de3d8d7fe623b8c9d67676f8113296ebdbb640.zip
Updates examples for FinderMethods [ci skip]
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 0abb801074..3d6a7a9d86 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -88,7 +88,7 @@ module ActiveRecord
# Person.where(["user_name = ?", user_name]).first
# Person.where(["user_name = :u", { :u => user_name }]).first
# Person.order("created_on DESC").offset(5).first
- # Person.first(3) # returns the first objects fetched by SELECT * FROM people LIMIT 3
+ # Person.first(3) # returns the first 3 objects fetched by SELECT * FROM people LIMIT 3
def first(limit = nil)
if limit
if order_values.empty? && primary_key
@@ -115,6 +115,15 @@ module ActiveRecord
# Person.last # returns the last object fetched by SELECT * FROM people
# Person.where(["user_name = ?", user_name]).last
# Person.order("created_on DESC").offset(5).last
+ # Person.last(3) # returns the last 3 objects fetched by SELECT * FROM people.
+ #
+ # Take note that in that last case, the results are sorted in ascending order:
+ #
+ # [#<Person id:2>, #<Person id:3>, #<Person id:4>]
+ #
+ # and not
+ #
+ # [#<Person id:4>, #<Person id:3>, #<Person id:2>]
def last(limit = nil)
if limit
if order_values.empty? && primary_key
@@ -133,6 +142,9 @@ module ActiveRecord
last or raise RecordNotFound
end
+ # Runs the query on the database and returns records with the used query
+ # methods.
+ #
# Examples:
#
# Person.all # returns an array of objects for all the rows fetched by SELECT * FROM people
@@ -167,8 +179,8 @@ module ActiveRecord
# ==== Examples
# Person.exists?(5)
# Person.exists?('5')
- # Person.exists?(:name => "David")
# Person.exists?(['name LIKE ?', "%#{query}%"])
+ # Person.exists?(:name => "David")
# Person.exists?
def exists?(id = false)
id = id.id if ActiveRecord::Model === id