Module: Mongoid::Relations

Extended by:
ActiveSupport::Concern
Includes:
Accessors, AutoSave, Builders, Cascading, Cyclic, Macros, Polymorphic, Reflections, Synchronization
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/options.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/conversions.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/embedded/sort.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/synchronization.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/targets/enumerable.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, ClassMethods, Conversions, Cyclic, Embedded, Macros, Options, Polymorphic, Referenced, Reflections, Synchronization, Targets Classes: Binding, Builder, Constraint, Many, Metadata, NestedBuilder, One, Proxy

Instance Method Summary collapse

Methods included from Synchronization

#remove_inverse_keys, #syncable?, #synced, #synced?, #update_inverse_keys

Methods included from Reflections

#reflect_on_all_associations, #reflect_on_association

Methods included from Macros

#associations

Methods included from Cascading

#cascade!

Methods included from Accessors

#build, #create_relation, #relation_exists?, #set_relation

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



60
61
62
# File 'lib/mongoid/relations.rb', line 60

def embedded?
  @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



72
73
74
# File 'lib/mongoid/relations.rb', line 72

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



84
85
86
# File 'lib/mongoid/relations.rb', line 84

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



96
97
98
# File 'lib/mongoid/relations.rb', line 96

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



108
109
110
# File 'lib/mongoid/relations.rb', line 108

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

#reload_relationsHash

Convenience method for iterating through the loaded relations and reloading them.

Examples:

Reload the relations.

document.reload_relations

Returns:

  • (Hash)

    The relations metadata.

Since:

  • 2.1.6



121
122
123
124
125
126
127
# File 'lib/mongoid/relations.rb', line 121

def reload_relations
  relations.each_pair do |name, meta|
    if instance_variable_defined?("@#{name}")
      remove_instance_variable("@#{name}")
    end
  end
end