From ce529b4759cec26578b1fabf8de883f31f32ef90 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 11 Aug 2010 14:45:07 -0700 Subject: dry up the hash dup and avoid sending nil values --- .../active_record/associations/belongs_to_association.rb | 12 ++++++++---- .../lib/active_record/associations/has_one_association.rb | 14 +++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 4558872a2b..2eb56e5cd3 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -49,12 +49,16 @@ module ActiveRecord else "find" end + + options = @reflection.options.dup + (options.keys - [:select, :include, :readonly]).each do |key| + options.delete key + end + options[:conditions] = conditions + the_target = @reflection.klass.send(find_method, @owner[@reflection.primary_key_name], - :select => @reflection.options[:select], - :conditions => conditions, - :include => @reflection.options[:include], - :readonly => @reflection.options[:readonly] + options ) if @owner[@reflection.primary_key_name] set_inverse_instance(the_target, @owner) the_target diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index 68b8b792ad..a6e6bfa356 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -79,13 +79,13 @@ module ActiveRecord private def find_target - the_target = @reflection.klass.find(:first, - :conditions => @finder_sql, - :select => @reflection.options[:select], - :order => @reflection.options[:order], - :include => @reflection.options[:include], - :readonly => @reflection.options[:readonly] - ) + options = @reflection.options.dup + (options.keys - [:select, :order, :include, :readonly]).each do |key| + options.delete key + end + options[:conditions] = @finder_sql + + the_target = @reflection.klass.find(:first, options) set_inverse_instance(the_target, @owner) the_target end -- cgit v1.2.3