diff --git a/activerecord/lib/active_record/associations/builder/singular_association.rb b/activerecord/lib/active_record/associations/builder/singular_association.rb index 76e48e66e581189eb257ef456e74359f0c6a825f..7bd894d6ab61a0df4fb6e79f93fb563ca0620bed 100644 --- a/activerecord/lib/active_record/associations/builder/singular_association.rb +++ b/activerecord/lib/active_record/associations/builder/singular_association.rb @@ -16,7 +16,7 @@ def define_accessors end # Defines the (build|create)_association methods for belongs_to or has_one association - + def define_constructors mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def build_#{name}(*args, &block) diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 4bd6669f3ccebf204657132b7be1e5f2c374b5f3..de2204da293392e059b54da6b7a9f2c74873af1b 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -21,14 +21,16 @@ def self.create(macro, name, scope, options, ar) end reflection = klass.new(macro, name, scope, options, ar) + add_reflection ar, name, reflection + reflection + end - if klass == AggregateReflection + def self.add_reflection(ar, name, reflection) + if reflection.class == AggregateReflection ar.aggregate_reflections = ar.aggregate_reflections.merge(name => reflection) else ar.reflections = ar.reflections.merge(name => reflection) end - - reflection end # \Reflection enables to interrogate Active Record classes and objects