Class | Mongoid::Relations::Metadata |
In: |
lib/mongoid/relations/metadata.rb
|
Parent: | Hash |
The "Grand Poobah" of information about any relation is this class. It contains everything you could ever possible want to know.
Gets a relation builder associated with the relation this metadata is for.
@example Get the builder.
metadata.builder(document)
@param [ Document ] base The base document. @param [ Object ] object A document or attributes to give the builder.
@return [ Builder ] The builder for the relation.
@since 2.0.0.rc.1
Returns the name of the class that this relation contains. If the class_name was provided as an option this will return that, otherwise it will determine the name from the name property.
@example Get the class name.
metadata.class_name
@return [ String ] The name of the relation‘s proxied class.
@since 2.0.0.rc.1
Get the foreign key contraint for the metadata.
@example Get the constaint.
metadata.constraint
@return [ Constraint ] The constraint.
@since 2.0.0.rc.1
Does the metadata have a dependent option?
@example Is the metadata performing cascades?
metadata.dependent?
@return [ true, false ] If the metadata cascades.
@since 2.1.0
Will determine if the relation is an embedded one or not. Currently only checks against embeds one and many.
@example Is the document embedded.
metadata.embedded?
@return [ true, false ] True if embedded, false if not.
@since 2.0.0.rc.1
Does this metadata have a forced nil inverse_of defined. (Used in many to manies)
@example Is this a forced nil inverse?
metadata.forced_nil_inverse?
@return [ true, false ] If inverse_of has been explicitly set to nil.
@since 2.3.3
Handles all the logic for figuring out what the foreign_key is for each relations query. The logic is as follows:
@example Get the foreign key.
metadata.foreign_key
@return [ String ] The foreign key for the relation.
@since 2.0.0.rc.1
Since a lot of the information from the metadata is inferred and not explicitly stored in the hash, the inspection needs to be much more detailed.
@example Inspect the metadata.
metadata.inspect
@return [ String ] Oodles of information in a nice format.
@since 2.0.0.rc.1
Get the name of the inverse relation if it exists. If this is a polymorphic relation then just return the :as option that was defined.
@example Get the name of the inverse.
metadata.inverse
@param [ Document ] other The document to aid in the discovery.
@return [ Symbol ] The inverse name.
@since 2.0.0.rc.1
Returns the inverse_class_name option of the relation.
@example Get the inverse_class_name option.
metadata.inverse_class_name
@return [ true, false ] The inverse_class_name option.
@since 2.1.0
Used for relational many to many only. This determines the name of the foreign key field on the inverse side of the relation, since in this case there are keys on both sides.
@example Find the inverse foreign key
metadata.inverse_foreign_key
@return [ String ] The foreign key on the inverse.
@since 2.0.0.rc.1
Returns the inverse_of option of the relation.
@example Get the inverse_of option.
metadata.inverse_of
@return [ true, false ] The inverse_of option.
@since 2.1.0
Does the metadata have a inverse_of option?
@example Is an inverse_of defined?
metadata.inverse_of?
@return [ true, false ] If the relation has an inverse_of defined.
@since 2.1.0
Gets a relation nested builder associated with the relation this metadata is for. Nested builders are used in conjunction with nested attributes.
@example Get the nested builder.
metadata.nested_builder(attributes, options)
@param [ Hash ] attributes The attributes to build the relation with. @param [ Hash ] options Options for the nested builder.
@return [ NestedBuilder ] The nested builder for the relation.
@since 2.0.0.rc.1
Returns default order for this association.
@example Get default order
metadata.order
@return [ Criterion::Complex, nil] nil if doesn‘t set
@since 2.1.0
Returns true if the relation is polymorphic.
@example Is the relation polymorphic?
metadata.polymorphic?
@return [ true, false ] True if the relation is polymorphic, false if not.
@since 2.0.0.rc.1
Are we validating this relation automatically?
@example Is automatic validation on?
metadata.validate?
@return [ true, false ] True unless explictly set to false.
@since 2.0.0.rc.1
Is this relation using Mongoid‘s internal versioning system?
@example Is this relation versioned?
metadata.versioned?
@return [ true, false ] If the relation uses Mongoid versioning.
@since 2.1.0