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

Ticket #8976: simple_optimized_exists.diff

File simple_optimized_exists.diff, 0.7 kB (added by hasmanyjosh, 1 year ago)

AR::Base exists? speedup

  • activerecord/lib/active_record/base.rb

    old new  
    447447      #   Person.exists?(:name => "David") 
    448448      #   Person.exists?(['name LIKE ?', "%#{query}%"]) 
    449449      def exists?(id_or_conditions) 
    450         !find(:first, :conditions => expand_id_conditions(id_or_conditions)).nil? 
     450        !find(:first, :select => "#{table_name}.#{primary_key}", :conditions => expand_id_conditions(id_or_conditions)).nil? 
    451451      rescue ActiveRecord::ActiveRecordError 
    452452        false 
    453453      end