Module: Dynamoid::Associations::ClassMethods

Defined in:
lib/dynamoid/associations.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(name, options = {}) ⇒ Object

create a belongs_to association for this document.

Parameters:

  • name (Symbol)

    the name of the association

  • options (Hash) (defaults to: {})

    options to pass to the association constructor

Options Hash (options):

  • :class (Class)

    the target class of the has_one association; that is, the has_many or has_one class

  • :class_name (Symbol)

    the name of the target class of the association; that is, the name of the has_many or has_one class

  • :inverse_of (Symbol)

    the name of the association on the target class; that is, if the class has a has_many or has_one association, the name of that association

Since:

  • 0.2.0



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

def belongs_to(name, options = {})
  association(:belongs_to, name, options)
end

#has_and_belongs_to_many(name, options = {}) ⇒ Object

create a has_and_belongs_to_many association for this document.

Parameters:

  • name (Symbol)

    the name of the association

  • options (Hash) (defaults to: {})

    options to pass to the association constructor

Options Hash (options):

  • :class (Class)

    the target class of the has_and_belongs_to_many association; that is, the belongs_to class

  • :class_name (Symbol)

    the name of the target class of the association; that is, the name of the belongs_to class

  • :inverse_of (Symbol)

    the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association

Since:

  • 0.2.0



76
77
78
# File 'lib/dynamoid/associations.rb', line 76

def has_and_belongs_to_many(name, options = {})
  association(:has_and_belongs_to_many, name, options)
end

#has_many(name, options = {}) ⇒ Object

create a has_many association for this document.

Parameters:

  • name (Symbol)

    the name of the association

  • options (Hash) (defaults to: {})

    options to pass to the association constructor

Options Hash (options):

  • :class (Class)

    the target class of the has_many association; that is, the belongs_to class

  • :class_name (Symbol)

    the name of the target class of the association; that is, the name of the belongs_to class

  • :inverse_of (Symbol)

    the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association

Since:

  • 0.2.0



37
38
39
# File 'lib/dynamoid/associations.rb', line 37

def has_many(name, options = {})
  association(:has_many, name, options)
end

#has_one(name, options = {}) ⇒ Object

create a has_one association for this document.

Parameters:

  • name (Symbol)

    the name of the association

  • options (Hash) (defaults to: {})

    options to pass to the association constructor

Options Hash (options):

  • :class (Class)

    the target class of the has_one association; that is, the belongs_to class

  • :class_name (Symbol)

    the name of the target class of the association; that is, the name of the belongs_to class

  • :inverse_of (Symbol)

    the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association

Since:

  • 0.2.0



50
51
52
# File 'lib/dynamoid/associations.rb', line 50

def has_one(name, options = {})
  association(:has_one, name, options)
end