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

- (Object) loaded

Returns the value of attribute loaded



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

def loaded
  @loaded
end

- (Object) name

Returns the value of attribute name



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

def name
  @name
end

- (Object) options

Returns the value of attribute options



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

def options
  @options
end

- (Object) source

Returns the value of attribute source



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

def source
  @source
end

Instance Method Details

- (Object) find_target



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

def find_target
end

- (Dynamoid::Association) initialize(source, name, options)

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

Since:

  • 0.2.0



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

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

- (Boolean) loaded?

Returns:

  • (Boolean)


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

def loaded?
  @loaded
end

- (Object) reset



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

def reset
  @target = nil
  @loaded = false
end

- (Object) target



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

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

  @target
end