Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10605: use_select_values.diff

File use_select_values.diff, 0.9 kB (added by fcheung, 6 months ago)
  • activerecord/lib/active_record/base.rb

    old new  
    548548      #   Person.exists?(:name => "David") 
    549549      #   Person.exists?(['name LIKE ?', "%#{query}%"]) 
    550550      def exists?(id_or_conditions) 
    551         !find(:first, :select => "#{quoted_table_name}.#{primary_key}", 
    552               :conditions => expand_id_conditions(id_or_conditions)).nil? 
     551        connection.select_values( 
     552          construct_finder_sql( 
     553            :select     => "#{quoted_table_name}.#{primary_key}",  
     554            :conditions => expand_id_conditions(id_or_conditions),  
     555            :limit      => 1 
     556          ),  
     557          "#{name} Exists" 
     558        ).any? 
    553559      end 
    554560 
    555561      # Creates an object (or multiple objects) and saves it to the database, if validations pass.