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
-
Chris Wanstrath December 4th, 2007 @ 12:11 PM
- → State changed from new to open
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
