diff options
author | Xavier Noria <fxn@hashref.com> | 2010-09-03 21:30:22 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-09-03 21:30:22 +0200 |
commit | 93acbf6bf31ca1802d7631c57da693a824456c4a (patch) | |
tree | 0c2be6d2c127abf50572dc86bf7dc182c00bb49c /activerecord/lib/active_record/relation/finder_methods.rb | |
parent | d28438caf2342be3df8421ed92b95e0510be8ac0 (diff) | |
parent | f8fb4651a7d8218befce48d66f4fadcea6ece37a (diff) | |
download | rails-93acbf6bf31ca1802d7631c57da693a824456c4a.tar.gz rails-93acbf6bf31ca1802d7631c57da693a824456c4a.tar.bz2 rails-93acbf6bf31ca1802d7631c57da693a824456c4a.zip |
Merge remote branch 'docrails/master'
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index bae31517c6..4ffb552690 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -21,7 +21,7 @@ module ActiveRecord # # ==== Parameters # - # * <tt>:conditions</tt> - An SQL fragment like "administrator = 1", <tt>[ "user_name = ?", username ]</tt>, + # * <tt>:conditions</tt> - An SQL fragment like "administrator = 1", <tt>["user_name = ?", username]</tt>, # or <tt>["user_name = :user_name", { :user_name => user_name }]</tt>. See conditions in the intro. # * <tt>:order</tt> - An SQL fragment like "created_at DESC, name". # * <tt>:group</tt> - An attribute name by which the result should be grouped. Uses the <tt>GROUP BY</tt> SQL-clause. @@ -54,7 +54,7 @@ module ActiveRecord # Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6) # Person.find([7, 17]) # returns an array for objects with IDs in (7, 17) # Person.find([1]) # returns an array for the object with ID = 1 - # Person.find(1, :conditions => "administrator = 1", :order => "created_on DESC") + # Person.where("administrator = 1").order("created_on DESC").find(1) # # Note that returned records may not be in the same order as the ids you # provide since database rows are unordered. Give an explicit <tt>:order</tt> @@ -63,23 +63,23 @@ module ActiveRecord # ==== Examples # # # find first - # Person.find(:first) # returns the first object fetched by SELECT * FROM people - # Person.find(:first, :conditions => [ "user_name = ?", user_name]) - # Person.find(:first, :conditions => [ "user_name = :u", { :u => user_name }]) - # Person.find(:first, :order => "created_on DESC", :offset => 5) + # Person.first # returns the first object fetched by SELECT * FROM people + # Person.where(["user_name = ?", user_name]).first + # Person.where(["user_name = :u", { :u => user_name }]).first + # Person.order("created_on DESC").offset(5).first # # # find last - # Person.find(:last) # returns the last object fetched by SELECT * FROM people - # Person.find(:last, :conditions => [ "user_name = ?", user_name]) - # Person.find(:last, :order => "created_on DESC", :offset => 5) + # 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 # # # find all - # Person.find(:all) # returns an array of objects for all the rows fetched by SELECT * FROM people - # Person.find(:all, :conditions => [ "category IN (?)", categories], :limit => 50) - # Person.find(:all, :conditions => { :friends => ["Bob", "Steve", "Fred"] } - # Person.find(:all, :offset => 10, :limit => 10) - # Person.find(:all, :include => [ :account, :friends ]) - # Person.find(:all, :group => "category") + # Person.all # returns an array of objects for all the rows fetched by SELECT * FROM people + # Person.where(["category IN (?)", categories]).limit(50).all + # Person.where({ :friends => ["Bob", "Steve", "Fred"] }).all + # Person.offset(10).limit(10).all + # Person.includes([:account, :friends]).all + # Person.group("category").all # # Example for find with a lock: Imagine two concurrent transactions: # each will read <tt>person.visits == 2</tt>, add 1 to it, and save, resulting @@ -88,7 +88,7 @@ module ActiveRecord # expected <tt>person.visits == 4</tt>. # # Person.transaction do - # person = Person.find(1, :lock => true) + # person = Person.lock(true).find(1) # person.visits += 1 # person.save! # end |