Permalink
Browse files

drying up construct_association

  • Loading branch information...
1 parent 8186c57 commit aa85a7a7e70ece22728aa3463fc3427c624d8296 @tenderlove tenderlove committed Sep 22, 2010
Showing with 15 additions and 15 deletions.
  1. +15 −15 activerecord/lib/active_record/associations.rb
@@ -1978,27 +1978,27 @@ def construct(parent, associations, joins, row)
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)

0 comments on commit aa85a7a

Please sign in to comment.