Module: Dynamoid::Associations::Association

Included in:
HasOne, ManyAssociation, SingleAssociation
Defined in:
lib/dynamoid/associations/association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loadedObject



12
13
14
# File 'lib/dynamoid/associations/association.rb', line 12

def loaded
  @loaded
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/dynamoid/associations/association.rb', line 10

def name
  @name
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/dynamoid/associations/association.rb', line 10

def options
  @options
end

#sourceObject

Returns the value of attribute source.



10
11
12
# File 'lib/dynamoid/associations/association.rb', line 10

def source
  @source
end

Instance Method Details

#declaration_field_nameObject



59
60
61
# File 'lib/dynamoid/associations/association.rb', line 59

def declaration_field_name
  "#{name}_ids"
end

#declaration_field_typeObject



64
65
66
# File 'lib/dynamoid/associations/association.rb', line 64

def declaration_field_type
  :set
end

#disassociate_sourceObject



69
70
71
72
73
# File 'lib/dynamoid/associations/association.rb', line 69

def disassociate_source
  Array(target).each do |target_entry|
    target_entry.send(target_association).disassociate(source.hash_key) if target_entry && target_association
  end
end

#find_targetObject



40
# File 'lib/dynamoid/associations/association.rb', line 40

def find_target; end

#initialize(source, name, options) ⇒ Dynamoid::Association

Create a new association.

Parameters:

  • source (Class)

    the source record of the association; that is, the record that you already have

  • name (Symbol)

    the name of the association

  • options (Hash)

    optional parameters for the association

Options Hash (options):

  • :class (Class)

    the target class of the association; that is, the class to which the association objects belong

  • :class_name (Symbol)

    the name of the target class of the association; only this or Class is necessary

  • :inverse_of (Symbol)

    the name of the association on the target class

  • :foreign_key (Symbol)

    the name of the field for belongs_to association

Returns:

  • (Dynamoid::Association)

    the actual association instance itself

Since:

  • 0.2.0



27
28
29
30
31
32
# File 'lib/dynamoid/associations/association.rb', line 27

def initialize(source, name, options)
  @name = name
  @options = options
  @source = source
  @loaded = false
end

#loaded?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/dynamoid/associations/association.rb', line 35

def loaded?
  @loaded
end

#resetObject



53
54
55
56
# File 'lib/dynamoid/associations/association.rb', line 53

def reset
  @target = nil
  @loaded = false
end

#targetObject



43
44
45
46
47
48
49
50
# File 'lib/dynamoid/associations/association.rb', line 43

def target
  unless loaded?
    @target = find_target
    @loaded = true
  end

  @target
end