diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-04-30 13:47:51 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-04-30 13:47:51 -0300 |
commit | ca0530a53f6b019b0f5eb9a8c5c8b0081cd20d12 (patch) | |
tree | b25b1e5fdedb0a6854302806f01d7a3da2fc3c88 /activerecord/lib | |
parent | 5b61168aafb28b9d4dcbe7651d6a5a63cdb68b32 (diff) | |
download | rails-ca0530a53f6b019b0f5eb9a8c5c8b0081cd20d12.tar.gz rails-ca0530a53f6b019b0f5eb9a8c5c8b0081cd20d12.tar.bz2 rails-ca0530a53f6b019b0f5eb9a8c5c8b0081cd20d12.zip |
exists? method now uses ARel
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5807d62f2a..26c11e2dda 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -688,14 +688,9 @@ module ActiveRecord #:nodoc: # Person.exists?(['name LIKE ?', "%#{query}%"]) # Person.exists? def exists?(id_or_conditions = {}) - connection.select_all( - construct_finder_sql( - :select => "#{quoted_table_name}.#{primary_key}", - :conditions => expand_id_conditions(id_or_conditions), - :limit => 1 - ), - "#{name} Exists" - ).size > 0 + construct_finder_arel({ + :conditions =>expand_id_conditions(id_or_conditions) + }).project(arel_table[primary_key]).take(1).count > 0 end # Creates an object (or multiple objects) and saves it to the database, if validations pass. @@ -1685,8 +1680,8 @@ module ActiveRecord #:nodoc: end end - def arel_table(table) - Arel(table) + def arel_table(table = table_name) + @arel_table = Arel(table) end def construct_finder_arel(options) |