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

Ticket #10605: without_sql_variable.diff

File without_sql_variable.diff, 0.9 kB (added by jamesh, 7 months ago)

Same as the original patch, but without the 'sql' variable.

  • 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_all( 
     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        ).size > 0 
    553559      end 
    554560 
    555561      # Creates an object (or multiple objects) and saves it to the database, if validations pass.