Method: Mongoid::Relations::Accessors::ClassMethods#getter

Defined in:
lib/mongoid/relations/accessors.rb

#getter(name, metadata) ⇒ Class

Defines the getter for the relation. Nothing too special here: just return the instance variable for the relation if it exists or build the thing.

Examples:

Set up the getter for the relation.

Person.getter("addresses", )

Parameters:

  • name (String, Symbol)

    The name of the relation.

  • metadata (Metadata)

    The metadata for the relation.

Returns:

  • (Class)

    The class being set up.

Since:

  • 2.0.0.rc.1



221
222
223
224
225
226
# File 'lib/mongoid/relations/accessors.rb', line 221

def getter(name, )
  re_define_method(name) do |reload = false|
    get_relation(name, , reload)
  end
  self
end