Method: Mongoid::Relations::Accessors::ClassMethods#ids_getter

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

#ids_getter(name, metadata) ⇒ Class

Defines the getter for the ids of documents in the relation. Should be specify only for referenced many relations.

Examples:

Set up the ids getter for the relation.

Person.ids_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.



238
239
240
241
242
243
244
# File 'lib/mongoid/relations/accessors.rb', line 238

def ids_getter(name, )
  ids_method = "#{name.to_s.singularize}_ids"
  re_define_method(ids_method) do
    send(name).only(:id).map(&:id)
  end
  self
end