method
association_constructor_method
association_constructor_method(constructor, reflection, association_proxy_class)
private
Hide source
# File activerecord/lib/active_record/associations.rb, line 1403 def association_constructor_method(constructor, reflection, association_proxy_class) define_method("#{constructor}_#{reflection.name}") do |*params| ivar = "@#{reflection.name}" attributees = params.first unless params.empty? replace_existing = params[1].nil? ? true : params[1] association = instance_variable_get(ivar) if instance_variable_defined?(ivar) if association.nil? association = association_proxy_class.new(self, reflection) instance_variable_set(ivar, association) end if association_proxy_class == HasOneAssociation association.send(constructor, attributees, replace_existing) else association.send(constructor, attributees) end end end