module Dynamoid::Associations::Association
Attributes
Public Class Methods
Create a new association.
@param [Class] source the source record of the association; that is, the record that you already have @param [Symbol] name the name of the association @param [Hash] options optional parameters for the association @option options [Class] :class the target class of the association; that is, the class to which the association objects belong @option options [Symbol] :class_name the name of the target class of the association; only this or Class is necessary @option options [Symbol] :inverse_of the name of the association on the target class
@return [Dynamoid::Association] the actual association instance itself
@since 0.2.0
# File lib/dynamoid/associations/association.rb, line 23 def initialize(source, name, options) @name = name @options = options @source = source @loaded = false end
Public Instance Methods
# File lib/dynamoid/associations/association.rb, line 34 def find_target end
# File lib/dynamoid/associations/association.rb, line 30 def loaded? @loaded end
# File lib/dynamoid/associations/association.rb, line 46 def reset @target = nil @loaded = false end
# File lib/dynamoid/associations/association.rb, line 37 def target unless loaded? @target = find_target @loaded = true end @target end
Private Instance Methods
The source's association attribute: the name of the association with _ids afterwards, like “users_ids”.
@since 0.2.0
# File lib/dynamoid/associations/association.rb, line 91 def source_attribute "#{name}_ids".to_sym end
The ids in the target association.
@since 0.2.0
# File lib/dynamoid/associations/association.rb, line 84 def source_class source.class end
The ids in the source association.
@since 0.2.0
# File lib/dynamoid/associations/association.rb, line 98 def source_ids source.send(source_attribute) || Set.new end
The target attribute: that is, the attribute on each object of the association that should reference the source.
@since 0.2.0
# File lib/dynamoid/associations/association.rb, line 70 def target_attribute "#{target_association}_ids".to_sym if target_association end
The target class, either inferred through the association's name or specified in options.
@since 0.2.0
# File lib/dynamoid/associations/association.rb, line 63 def target_class options[:class] || target_class_name.constantize end
The target class name, either inferred through the association's name or specified in options.
@since 0.2.0
# File lib/dynamoid/associations/association.rb, line 56 def target_class_name options[:class_name] || name.to_s.classify end
The ids in the target association.
@since 0.2.0
# File lib/dynamoid/associations/association.rb, line 77 def target_ids target.send(target_attribute) || Set.new end