Module: Mongoid::Association::Macros::ClassMethods
- Defined in:
- lib/mongoid/association/macros.rb
Instance Method Summary collapse
-
#belongs_to(name, options = {}, &block) ⇒ Object
Adds a referenced association from the child Document to a Document in another database or collection.
-
#embedded_in(name, options = {}, &block) ⇒ Object
Adds the association back to the parent document.
-
#embeds_many(name, options = {}, &block) ⇒ Object
Adds the association from a parent document to its children.
-
#embeds_one(name, options = {}, &block) ⇒ Object
Adds the association from a parent document to its child.
-
#has_and_belongs_to_many(name, options = {}, &block) ⇒ Object
Adds a referenced many-to-many association between many of this Document and many of another Document.
-
#has_many(name, options = {}, &block) ⇒ Object
Adds a referenced association from a parent Document to many Documents in another database or collection.
-
#has_one(name, options = {}, &block) ⇒ Object
Adds a referenced association from the child Document to a Document in another database or collection.
Instance Method Details
#belongs_to(name, options = {}, &block) ⇒ Object
Adds a referenced association from the child Document to a Document in another database or collection.
123 124 125 |
# File 'lib/mongoid/association/macros.rb', line 123 def belongs_to(name, = {}, &block) define_association!(__method__, name, , &block) end |
#embedded_in(name, options = {}, &block) ⇒ Object
Adds the association back to the parent document. This macro is necessary to set the references from the child back to the parent document. If a child does not define this association calling persistence methods on the child object will cause a save to fail.
55 56 57 |
# File 'lib/mongoid/association/macros.rb', line 55 def (name, = {}, &block) define_association!(__method__, name, , &block) end |
#embeds_many(name, options = {}, &block) ⇒ Object
Adds the association from a parent document to its children. The name of the association needs to be a pluralized form of the child class name.
78 79 80 |
# File 'lib/mongoid/association/macros.rb', line 78 def (name, = {}, &block) define_association!(__method__, name, , &block) end |
#embeds_one(name, options = {}, &block) ⇒ Object
Adds the association from a parent document to its child. The name of the association needs to be a singular form of the child class name.
101 102 103 |
# File 'lib/mongoid/association/macros.rb', line 101 def (name, = {}, &block) define_association!(__method__, name, , &block) end |
#has_and_belongs_to_many(name, options = {}, &block) ⇒ Object
Adds a referenced many-to-many association between many of this Document and many of another Document.
169 170 171 |
# File 'lib/mongoid/association/macros.rb', line 169 def has_and_belongs_to_many(name, = {}, &block) define_association!(__method__, name, , &block) end |
#has_many(name, options = {}, &block) ⇒ Object
Adds a referenced association from a parent Document to many Documents in another database or collection.
145 146 147 |
# File 'lib/mongoid/association/macros.rb', line 145 def has_many(name, = {}, &block) define_association!(__method__, name, , &block) end |
#has_one(name, options = {}, &block) ⇒ Object
Adds a referenced association from the child Document to a Document in another database or collection.
191 192 193 |
# File 'lib/mongoid/association/macros.rb', line 191 def has_one(name, = {}, &block) define_association!(__method__, name, , &block) end |