diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-11 14:45:07 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-11 15:00:02 -0700 |
commit | ce529b4759cec26578b1fabf8de883f31f32ef90 (patch) | |
tree | d6345f94063577b02d1531abb89fb5f4e9ebb8d9 /activerecord/lib | |
parent | 0f502ab88fb9a9be10ed7c28f649505651ecf96e (diff) | |
download | rails-ce529b4759cec26578b1fabf8de883f31f32ef90.tar.gz rails-ce529b4759cec26578b1fabf8de883f31f32ef90.tar.bz2 rails-ce529b4759cec26578b1fabf8de883f31f32ef90.zip |
dry up the hash dup and avoid sending nil values
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/belongs_to_association.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_one_association.rb | 14 |
2 files changed, 15 insertions, 11 deletions
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 |