Module: Mongoid::Association::Reflections::ClassMethods

Defined in:
build/mongoid-master/lib/mongoid/association/reflections.rb

Instance Method Summary collapse

Instance Method Details

#reflect_on_all_associations(*macros) ⇒ Array<Association>

Returns all association metadata for the supplied macros.

Examples:

Find multiple association metadata by macro.

Person.reflect_on_all_associations(:embeds_many)

Parameters:

  • macros (Array<Symbol>)

    The association macros.

Returns:

  • (Array<Association>)

    The matching association metadata.



58
59
60
61
62
63
64
65
66
# File 'build/mongoid-master/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) ⇒ Association

Returns the association metadata for the supplied name.

Examples:

Find association metadata by name.

Person.reflect_on_association(:addresses)

Parameters:

  • name (String, Symbol)

    The name of the association to find.

Returns:



46
47
48
# File 'build/mongoid-master/lib/mongoid/association/reflections.rb', line 46

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