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

Ticket #8470: streamline_generated_method_calls.patch

File streamline_generated_method_calls.patch, 1.6 kB (added by seth, 2 years ago)
  • lib/active_record/base.rb

    old new  
    16211621      def id 
    16221622        attr_name = self.class.primary_key 
    16231623        column = column_for_attribute(attr_name) 
    1624         define_read_method(:id, attr_name, column) if self.class.generate_read_methods 
    1625         read_attribute(attr_name) 
     1624         
     1625        if self.class.generate_read_methods 
     1626          define_read_method(:id, attr_name, column) 
     1627          # now that the method exists, call it 
     1628          self.send attr_name.to_sym 
     1629        else 
     1630          read_attribute(attr_name) 
     1631        end 
    16261632      end 
    16271633 
    16281634      # Enables Active Record objects to be used as URL parameters in Action Pack automatically. 
     
    19761982            (md = /\?$/.match(method_name) and 
    19771983            @attributes.include?(query_method_name = md.pre_match) and 
    19781984            method_name = query_method_name) 
    1979           define_read_methods if self.class.read_methods.empty? && self.class.generate_read_methods 
    1980           md ? query_attribute(method_name) : read_attribute(method_name) 
     1985          if self.class.read_methods.empty? && self.class.generate_read_methods 
     1986            define_read_methods 
     1987            # now that the method exists, call it 
     1988            self.send method_id.to_sym 
     1989          else 
     1990            md ? query_attribute(method_name) : read_attribute(method_name) 
     1991          end 
    19811992        elsif self.class.primary_key.to_s == method_name 
    19821993          id 
    19831994        elsif md = self.class.match_attribute_method?(method_name)