aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/associations.rb30
1 files changed, 15 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 4fcc754a23..e8a5364cd7 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1978,27 +1978,27 @@ module ActiveRecord
def construct_association(record, join, row)
return if record.id.to_s != join.parent.record_id(row).to_s
- case join.reflection.macro
- when :has_many, :has_and_belongs_to_many
- collection = record.send(join.reflection.name)
- collection.loaded
-
- return if row[join.aliased_primary_key].nil?
- association = join.instantiate(row)
- collection.target.push(association)
- collection.__send__(:set_inverse_instance, association, record)
- when :has_one
+ macro = join.reflection.macro
+ if macro == :has_one
return if record.instance_variable_defined?("@#{join.reflection.name}")
association = join.instantiate(row) unless row[join.aliased_primary_key].nil?
set_target_and_inverse(join, association, record)
- when :belongs_to
+ else
return if row[join.aliased_primary_key].nil?
association = join.instantiate(row)
- set_target_and_inverse(join, association, record)
- else
- raise ConfigurationError, "unknown macro: #{join.reflection.macro}"
+ case macro
+ when :has_many, :has_and_belongs_to_many
+ collection = record.send(join.reflection.name)
+ collection.loaded
+ collection.target.push(association)
+ collection.__send__(:set_inverse_instance, association, record)
+ when :belongs_to
+ set_target_and_inverse(join, association, record)
+ else
+ raise ConfigurationError, "unknown macro: #{join.reflection.macro}"
+ end
end
- return association
+ association
end
def set_target_and_inverse(join, association, record)