aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2007-12-05 17:35:17 +0000
committerMarcel Molina <marcel@vernix.org>2007-12-05 17:35:17 +0000
commit971ed153608c571c32416cad0afa9126d122602f (patch)
tree9620e442403e3c537b5ce8da6aa8d089868e3336 /activerecord/lib/active_record/base.rb
parenta23bea7c0d16d159b38650770baafd0c09d2ca78 (diff)
downloadrails-971ed153608c571c32416cad0afa9126d122602f.tar.gz
rails-971ed153608c571c32416cad0afa9126d122602f.tar.bz2
rails-971ed153608c571c32416cad0afa9126d122602f.zip
Document API for exists?'s parameter and provide examples of usage. Closes #7913 [fearoffish]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8297 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 5330899ece..4b1693272f 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -461,9 +461,18 @@ module ActiveRecord #:nodoc:
connection.select_all(sanitize_sql(sql), "#{name} Load").collect! { |record| instantiate(record) }
end
- # Returns true if the given +id+ represents the primary key of a record in the database, false otherwise.
- # You can also pass a set of SQL conditions.
- # Example:
+ # Checks whether a record exists in the database that matches conditions given. These conditions
+ # can either be a single integer representing a primary key id to be found, or a condition to be
+ # matched like using ActiveRecord#find.
+ #
+ # The +id_or_conditions+ parameter can be an Integer or a String if you want to search the primary key
+ # column of the table for a matching id, or if you're looking to match against a condition you can use
+ # an Array or a Hash.
+ #
+ # Possible gotcha: You can't pass in a condition as a string e.g. "name = 'Jamie'", this would be
+ # sanitized and then queried against the primary key column as "id = 'name = \'Jamie"
+ #
+ # ==== Examples
# Person.exists?(5)
# Person.exists?('5')
# Person.exists?(:name => "David")