aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-21 21:01:48 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-21 21:01:48 -0700
commitaa85a7a7e70ece22728aa3463fc3427c624d8296 (patch)
treeed91b211d91bc96b57c73b25e9de26423299c3c1 /activerecord/lib
parent8186c5736bef4597dd8c1f94bd6343eae7bda70e (diff)
downloadrails-aa85a7a7e70ece22728aa3463fc3427c624d8296.tar.gz
rails-aa85a7a7e70ece22728aa3463fc3427c624d8296.tar.bz2
rails-aa85a7a7e70ece22728aa3463fc3427c624d8296.zip
drying up construct_association
Diffstat (limited to 'activerecord/lib')
-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)