Module: Mongoid::Relations::Reflections::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#reflect_on_all_associations(*macros) ⇒ Array<Metadata>

Returns all relation metadata for the supplied macros.

Examples:

Find multiple relation metadata by macro.

Person.reflect_on_all_associations(:embeds_many)

Parameters:

  • *macros (Array<String, Symbol>)

    The relation macros.

Returns:

  • (Array<Metadata>)

    The matching relation metadata.



56
57
58
# File 'lib/mongoid/relations/reflections.rb', line 56

def reflect_on_all_associations(*macros)
  relations.values.select { |meta| macros.include?(meta.macro) }
end

#reflect_on_association(name) ⇒ Metadata

Returns the relation metadata for the supplied name.

Examples:

Find relation metadata by name.

Person.reflect_on_association(:addresses)

Parameters:

  • name (String, Symbol)

    The name of the relation to find.

Returns:

  • (Metadata)

    The matching relation metadata.



44
45
46
# File 'lib/mongoid/relations/reflections.rb', line 44

def reflect_on_association(name)
  relations[name.to_s]
end