Class: Mongoid::Relations::Cascading::Delete
- Inherits:
-
Object
- Object
- Mongoid::Relations::Cascading::Delete
- Defined in:
- lib/mongoid/relations/cascading/delete.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#relation ⇒ Object
Returns the value of attribute relation.
Instance Method Summary collapse
-
#cascade ⇒ Object
Execute the cascading deletion for the relation if it already exists.
-
#initialize(document, metadata) ⇒ Strategy
constructor
Initialize the new cascade strategy, which will set up the relation and the metadata.
Constructor Details
#initialize(document, metadata) ⇒ Strategy
Initialize the new cascade strategy, which will set up the relation and the metadata.
19 20 21 22 |
# File 'lib/mongoid/relations/cascading/delete.rb', line 19 def initialize(document, ) @document, @metadata = document, @relation = document.send(.name) end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
7 8 9 |
# File 'lib/mongoid/relations/cascading/delete.rb', line 7 def document @document end |
#metadata ⇒ Object
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/mongoid/relations/cascading/delete.rb', line 7 def @metadata end |
#relation ⇒ Object
Returns the value of attribute relation.
7 8 9 |
# File 'lib/mongoid/relations/cascading/delete.rb', line 7 def relation @relation end |
Instance Method Details
#cascade ⇒ Object
Execute the cascading deletion for the relation if it already exists. This should be optimized in the future potentially not to load all objects from the db.
32 33 34 35 36 37 38 39 40 |
# File 'lib/mongoid/relations/cascading/delete.rb', line 32 def cascade if relation if relation.cascades.empty? relation.clear else ::Array.wrap(relation).each { |doc| doc.delete } end end end |