aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-12-27 18:10:26 +0530
committerPratik Naik <pratiknaik@gmail.com>2009-12-27 18:10:26 +0530
commit59cf5e7bf293f30ef4984842a1bce0d63870fc69 (patch)
tree107922be5f5c99b451fd0634aba7b270fc658b95
parent2c8f83556bf3ec9861315e11bc070753ef6bd97c (diff)
downloadrails-59cf5e7bf293f30ef4984842a1bce0d63870fc69.tar.gz
rails-59cf5e7bf293f30ef4984842a1bce0d63870fc69.tar.bz2
rails-59cf5e7bf293f30ef4984842a1bce0d63870fc69.zip
Make Model.exists? use relation.exists?
-rwxr-xr-xactiverecord/lib/active_record/base.rb19
1 files changed, 7 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 73bd407f8f..5ea1bc983e 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -732,10 +732,13 @@ module ActiveRecord #:nodoc:
# Person.exists?(:name => "David")
# Person.exists?(['name LIKE ?', "%#{query}%"])
# Person.exists?
- def exists?(id_or_conditions = {})
- find_initial(
- :select => "#{quoted_table_name}.#{primary_key}",
- :conditions => expand_id_conditions(id_or_conditions)) ? true : false
+ def exists?(id_or_conditions = nil)
+ case id_or_conditions
+ when Array, Hash
+ where(id_or_conditions).exists?
+ else
+ scoped.exists?(id_or_conditions)
+ end
end
# Creates an object (or multiple objects) and saves it to the database, if validations pass.
@@ -1874,14 +1877,6 @@ module ActiveRecord #:nodoc:
end
end
- # Interpret Array and Hash as conditions and anything else as an id.
- def expand_id_conditions(id_or_conditions)
- case id_or_conditions
- when Array, Hash then id_or_conditions
- else sanitize_sql(primary_key => id_or_conditions)
- end
- end
-
protected
# Scope parameters to method calls within the block. Takes a hash of method_name => parameters hash.
# method_name may be <tt>:find</tt> or <tt>:create</tt>. <tt>:find</tt> parameters may include the <tt>:conditions</tt>, <tt>:joins</tt>,