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

Returns the value of attribute loaded.



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

def loaded
  @loaded
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#declaration_field_nameObject



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

def declaration_field_name
  "#{name}_ids"
end

#declaration_field_typeObject



56
57
58
# File 'lib/dynamoid/associations/association.rb', line 56

def declaration_field_type
  :set
end

#find_targetObject



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

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



24
25
26
27
28
29
# File 'lib/dynamoid/associations/association.rb', line 24

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

#loaded?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/dynamoid/associations/association.rb', line 31

def loaded?
  @loaded
end

#resetObject



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

def reset
  @target = nil
  @loaded = false
end

#targetObject



38
39
40
41
42
43
44
45
# File 'lib/dynamoid/associations/association.rb', line 38

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

  @target
end