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

Ticket #10605: using_select_value.diff

File using_select_value.diff, 0.9 kB (added by protocool, 6 months ago)

Again, same as original, bu also eliminates sql variable and uses select_value connection call

  • 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_value( 
     552          construct_finder_sql(:select => "#{quoted_table_name}.#{primary_key}", 
     553            :conditions => expand_id_conditions(id_or_conditions), :limit => 1), 
     554          "#{name} Exists" 
     555        ).nil? 
    553556      end 
    554557 
    555558      # Creates an object (or multiple objects) and saves it to the database, if validations pass.