From ca0530a53f6b019b0f5eb9a8c5c8b0081cd20d12 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Thu, 30 Apr 2009 13:47:51 -0300 Subject: exists? method now uses ARel --- activerecord/lib/active_record/base.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'activerecord/lib/active_record/base.rb') 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) -- cgit v1.2.3