metadata

All relations in Mongoid contain metadata that holds information about the relation in question, and is a valuable tool for third party developers to use to extend Mongoid.

You can access the metadata of the relation in a few different ways.

# Get the metadata for a named relation from the class or document.
Model.reflect_on_association(:relation_name)
model.reflect_on_association(:relation_name)

# Get the metadata that the current object has in its relation.
model.metadata

# Get the metadata with a specific relation itself on a specific
# document.
person.addresses.metadata

the metadata object

The metadata object itself contains more information than one might know what to do with.

  • Metadata#class_name
  • Metadata#embedded?
  • Metadata#extension
  • Metadata#foreign_key
  • Metadata#foreign_key_default
  • Metadata#foreign_key_setter
  • Metadata#indexed?
  • Metadata#inverse
  • Metadata#inverse_foreign_key
  • Metadata#inverse_klass
  • Metadata#inverse_setter
  • Metadata#inverse_type
  • Metadata#inverse_type_setter
  • Metadata#key
  • Metadata#klass
  • Metadata#macro
  • Metadata#polymorphic?
  • Metadata#setter
  • Metadata#stores_foreign_key?
  • Metadata#validate?