Module: Mongoid::Relations

Extended by:
ActiveSupport::Concern
Includes:
Accessors, AutoSave, Builders, Cascading, Cyclic, Macros, Polymorphic, Reflections
Included in:
Components
Defined in:
lib/mongoid/relations.rb,
lib/mongoid/relations/one.rb,
lib/mongoid/relations/many.rb,
lib/mongoid/relations/proxy.rb,
lib/mongoid/relations/cyclic.rb,
lib/mongoid/relations/macros.rb,
lib/mongoid/relations/binding.rb,
lib/mongoid/relations/builder.rb,
lib/mongoid/relations/builders.rb,
lib/mongoid/relations/metadata.rb,
lib/mongoid/relations/accessors.rb,
lib/mongoid/relations/auto_save.rb,
lib/mongoid/relations/cascading.rb,
lib/mongoid/relations/constraint.rb,
lib/mongoid/relations/embedded/in.rb,
lib/mongoid/relations/polymorphic.rb,
lib/mongoid/relations/reflections.rb,
lib/mongoid/relations/embedded/one.rb,
lib/mongoid/relations/embedded/many.rb,
lib/mongoid/relations/referenced/in.rb,
lib/mongoid/relations/nested_builder.rb,
lib/mongoid/relations/referenced/one.rb,
lib/mongoid/relations/embedded/atomic.rb,
lib/mongoid/relations/referenced/many.rb,
lib/mongoid/relations/cascading/delete.rb,
lib/mongoid/relations/referenced/batch.rb,
lib/mongoid/relations/cascading/destroy.rb,
lib/mongoid/relations/cascading/nullify.rb,
lib/mongoid/relations/cascading/strategy.rb,
lib/mongoid/relations/embedded/atomic/set.rb,
lib/mongoid/relations/bindings/embedded/in.rb,
lib/mongoid/relations/builders/embedded/in.rb,
lib/mongoid/relations/embedded/atomic/pull.rb,
lib/mongoid/relations/bindings/embedded/one.rb,
lib/mongoid/relations/builders/embedded/one.rb,
lib/mongoid/relations/embedded/atomic/unset.rb,
lib/mongoid/relations/bindings/embedded/many.rb,
lib/mongoid/relations/bindings/referenced/in.rb,
lib/mongoid/relations/builders/embedded/many.rb,
lib/mongoid/relations/builders/referenced/in.rb,
lib/mongoid/relations/bindings/referenced/one.rb,
lib/mongoid/relations/builders/referenced/one.rb,
lib/mongoid/relations/referenced/batch/insert.rb,
lib/mongoid/relations/referenced/many_to_many.rb,
lib/mongoid/relations/bindings/referenced/many.rb,
lib/mongoid/relations/builders/referenced/many.rb,
lib/mongoid/relations/embedded/atomic/push_all.rb,
lib/mongoid/relations/embedded/atomic/operation.rb,
lib/mongoid/relations/builders/nested_attributes/one.rb,
lib/mongoid/relations/builders/nested_attributes/many.rb,
lib/mongoid/relations/bindings/referenced/many_to_many.rb,
lib/mongoid/relations/builders/referenced/many_to_many.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Accessors, AutoSave, Bindings, Builders, Cascading, Cyclic, Embedded, Macros, Polymorphic, Referenced, Reflections Classes: Binding, Builder, Constraint, Many, Metadata, NestedBuilder, One, Proxy

Instance Method Summary collapse

Methods included from Cascading

#cascade!

Methods included from Accessors

#build, #create_relation, #options, #relation_exists?, #set, #substitute

Instance Method Details

#embedded?true, false

Determine if the document itself is embedded in another document via the proper channels. (If it has a parent document.)

Examples:

Is the document embedded?

address.embedded?

Returns:

  • (true, false)

    True if the document has a parent document.

Since:

  • 2.0.0.rc.1



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

def embedded?
  cyclic ? _parent.present? : self.class.embedded?
end

#embedded_many?true, false

Determine if the document is part of an embeds_many relation.

Examples:

Is the document in an embeds many?

address.embedded_many?

Returns:

  • (true, false)

    True if in an embeds many.

Since:

  • 2.0.0.rc.1



67
68
69
# File 'lib/mongoid/relations.rb', line 67

def embedded_many?
   && .macro == :embeds_many
end

#embedded_one?true, false

Determine if the document is part of an embeds_one relation.

Examples:

Is the document in an embeds one?

address.embedded_one?

Returns:

  • (true, false)

    True if in an embeds one.

Since:

  • 2.0.0.rc.1



79
80
81
# File 'lib/mongoid/relations.rb', line 79

def embedded_one?
   && .macro == :embeds_one
end

#referenced_many?true, false

Determine if the document is part of an references_many relation.

Examples:

Is the document in a references many?

post.referenced_many?

Returns:

  • (true, false)

    True if in a references many.

Since:

  • 2.0.0.rc.1



91
92
93
# File 'lib/mongoid/relations.rb', line 91

def referenced_many?
   && .macro == :references_many
end

#referenced_one?true, false

Determine if the document is part of an references_one relation.

Examples:

Is the document in a references one?

address.referenced_one?

Returns:

  • (true, false)

    True if in a references one.

Since:

  • 2.0.0.rc.1



103
104
105
# File 'lib/mongoid/relations.rb', line 103

def referenced_one?
   && .macro == :references_one
end