From 8219691ef29cdcd04b784e20e3e790d8e952285c Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@gmail.com>
Date: Fri, 11 Oct 2013 15:30:25 -0700
Subject: belongs_to can be treated the same way as has_one

---
 .../lib/active_record/associations/join_dependency.rb   | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

(limited to 'activerecord/lib')

diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index d61e209e55..d91307d972 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -221,23 +221,16 @@ module ActiveRecord
 
       def construct_association(record, join_part, row)
         macro = join_part.reflection.macro
-        if macro == :has_one
+        if macro == :has_one || macro == :belongs_to
           return record.association(join_part.reflection.name).target if record.association_cache.key?(join_part.reflection.name)
           association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
           set_target_and_inverse(join_part, association, record)
         else
           association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
-          case macro
-          when :has_many
-            other = record.association(join_part.reflection.name)
-            other.loaded!
-            other.target.push(association) if association
-            other.set_inverse_instance(association)
-          when :belongs_to
-            set_target_and_inverse(join_part, association, record)
-          else
-            raise ConfigurationError, "unknown macro: #{join_part.reflection.macro}"
-          end
+          other = record.association(join_part.reflection.name)
+          other.loaded!
+          other.target.push(association) if association
+          other.set_inverse_instance(association)
         end
         association
       end
-- 
cgit v1.2.3