Module: Mongoid::Relations::Cyclic::ClassMethods

Defined in:
lib/mongoid/relations/cyclic.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#recursively_embeds_manyObject

Create a cyclic embedded relation that creates a tree hierarchy for the document and many embedded child documents.

This provides the default nomenclature for accessing a parent document or its children.

Examples:

Set up a recursive embeds many.


class Role
  include Mongoid::Document
  recursively_embeds_many
end

The previous example is a shorcut for this.


class Role
  include Mongoid::Document
  embeds_many :child_roles, :class_name => "Role", :cyclic => true
  embedded_in :parent_role, :class_name => "Role", :cyclic => true
end

Since:

  • 2.0.0.rc.1



38
39
40
41
42
# File 'lib/mongoid/relations/cyclic.rb', line 38

def recursively_embeds_many
  self.cyclic = true
  embeds_many cyclic_child_name, :class_name => self.name, :cyclic => true
  embedded_in cyclic_parent_name, :class_name => self.name, :cyclic => true
end

#recursively_embeds_oneObject

Create a cyclic embedded relation that creates a single self referencing relationship for a parent and a single child.

This provides the default nomenclature for accessing a parent document or its children.

Examples:

Set up a recursive embeds one.


class Role
  include Mongoid::Document
  recursively_embeds_one
end

The previous example is a shorcut for this.


class Role
  include Mongoid::Document
  embeds_one :child_role, :class_name => "Role", :cyclic => true
  embedded_in :parent_role, :class_name => "Role", :cyclic => true
end

Since:

  • 2.0.0.rc.1



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

def recursively_embeds_one
  self.cyclic = true
  embeds_one cyclic_child_name(false), :class_name => self.name, :cyclic => true
  embedded_in cyclic_parent_name, :class_name => self.name, :cyclic => true
end