class Cequel::Record::HasManyAssociation

Represents a child association declared by {Associations::ClassMethods#has_many has_many}.

@see Associations::ClassMethods#child_associations @since 1.0.0

Attributes

association_class_name[R]

@return [Symbol] name of the child class that this association contains

dependent[R]

@return [Boolean] behavior for propagating destruction from parent to

children
name[R]

@return [Symbol] name of this association

owner_class[R]

@return [Class] Record class that declares this association

Public Class Methods

new(owner_class, name, options = {}) click to toggle source

@param owner_class [Class] Record class that declares this association @param name [Symbol] name of the association @param options [Options] options for the association @option options [Symbol] :class_name name of the child class @option options [Boolean] :dependent propagation behavior for destroy

@api private

# File lib/cequel/record/has_many_association.rb, line 30
def initialize(owner_class, name, options = {})
  options.assert_valid_keys(:class_name, :dependent)

  @owner_class, @name = owner_class, name
  @association_class_name =
    options.fetch(:class_name, name.to_s.classify)
  case options[:dependent]
  when :destroy, :delete, nil
    @dependent = options[:dependent]
  else
    fail ArgumentError,
         "Invalid :dependent option #{options[:dependent].inspect}. " \
         "Valid values are :destroy, :delete"
  end
end

Public Instance Methods

association_class() click to toggle source

@return [Class] class of child association

# File lib/cequel/record/has_many_association.rb, line 49
def association_class
  @association_class ||= association_class_name.constantize
end
instance_variable_name() click to toggle source

@private

# File lib/cequel/record/has_many_association.rb, line 54
def instance_variable_name
  @instance_variable_name ||= :"@#{name}"
end