#169 open
Lourens Naude

Simple belongs_to && variants optimization

Reported by Lourens Naude | December 4th, 2007 @ 01:24 AM

Chris,

We're using these monkey patches in pre-production ... almost 0 overhead with regards to model changes and works well alongside non cached Models .... thoughts ?


module ActiveRecord
  module Associations
    class BelongsToAssociation
 
      private
        def find_target
          @reflection.klass.send( (@reflection.klass.respond_to?( :get_cache ) ? :get_cache : :find ),
            @owner[@reflection.primary_key_name], 
            :conditions => conditions,
            :include    => @reflection.options[:include]
          )
        end 
         
    end
  end
end      

module ActiveRecord
  module Associations
    class BelongsToPolymorphicAssociation
      
      private
      def find_target
        return nil if association_class.nil?
        _find_by_method = (association_class.respond_to?( :get_cache ) ? :get_cache : :find )   
        if @reflection.options[:conditions]
          association_class.send( _find_by_method,
            @owner[@reflection.primary_key_name], 
            :conditions => conditions,
            :include    => @reflection.options[:include]
          )
        else
          association_class.send( _find_by_method, @owner[@reflection.primary_key_name], :include => @reflection.options[:include])
        end
      end  
    end    
  end
end  

  • Lourens

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

Tags

Pages