Flowdock
method

association_constructor_method

Importance_0
v1.0.0 - Show latest stable - 0 notes - Class: ActiveRecord::Associations::ClassMethods
association_constructor_method(constructor, association_name, association_class_name, association_class_primary_key_name, options, association_proxy_class) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/associations.rb, line 826
        def association_constructor_method(constructor, association_name, association_class_name, association_class_primary_key_name, options, association_proxy_class)
          define_method("#{constructor}_#{association_name}") do |*params|
            attributees      = params.first unless params.empty?
            replace_existing = params[1].nil? ? true : params[1]
            association      = instance_variable_get("@#{association_name}")

            if association.nil?
              association = association_proxy_class.new(self,
                association_name, association_class_name,
                association_class_primary_key_name, options)
              instance_variable_set("@#{association_name}", association)
            end

            if association_proxy_class == HasOneAssociation
              association.send(constructor, attributees, replace_existing)
            else
              association.send(constructor, attributees)
            end
          end
        end
Register or log in to add new notes.