diff options
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-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) |