diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-11 15:30:25 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-11 15:30:25 -0700 |
commit | 8219691ef29cdcd04b784e20e3e790d8e952285c (patch) | |
tree | af61514c025e4935887a75b086d9687cb25deeb8 /activerecord/lib | |
parent | 3a8892aae21c624ca6daf1c02188f361491de270 (diff) | |
download | rails-8219691ef29cdcd04b784e20e3e790d8e952285c.tar.gz rails-8219691ef29cdcd04b784e20e3e790d8e952285c.tar.bz2 rails-8219691ef29cdcd04b784e20e3e790d8e952285c.zip |
belongs_to can be treated the same way as has_one
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 17 |
1 files changed, 5 insertions, 12 deletions
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 |