module Mongoid::Association::Reflections::ClassMethods

Public Instance Methods

reflect_on_all_associations(*macros) click to toggle source

Returns all association metadata for the supplied macros.

@example Find multiple association metadata by macro.

Person.reflect_on_all_associations(:embeds_many)

@param [ Array<Symbol> ] macros The association macros.

@return [ Array<Association> ] The matching association metadata.

# File lib/mongoid/association/reflections.rb, line 58
def reflect_on_all_associations(*macros)
  all_associations = relations.values
  unless macros.empty?
    all_associations.select! do |reflection|
      macros.include?(Association::MACRO_MAPPING.key(reflection.class))
    end
  end
  all_associations
end
reflect_on_association(name) click to toggle source

Returns the association metadata for the supplied name.

@example Find association metadata by name.

Person.reflect_on_association(:addresses)

@param [ String, Symbol ] name The name of the association to find.

@return [ Association ] The matching association metadata.

# File lib/mongoid/association/reflections.rb, line 46
def reflect_on_association(name)
  relations[name.to_s]
end