Method: Parse::Core::Actions#relation_change_operations
- Defined in:
- lib/parse/model/core/actions.rb
#relation_change_operations ⇒ Array
Generates an array with two entries for addition and removal operations. The first entry of the array will contain a hash of all the change operations regarding adding new relational objects. The second entry in the array is a hash of all the change operations regarding removing relation objects from this field.
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'lib/parse/model/core/actions.rb', line 582 def relation_change_operations return [{}, {}] unless relation_changes? additions = [] removals = [] # go through all the additions of a collection and generate an action to add. relation_updates.each do |field, collection| if collection.additions.count > 0 additions.push Parse::RelationAction.new(field, objects: collection.additions, polarity: true) end # go through all the additions of a collection and generate an action to remove. if collection.removals.count > 0 removals.push Parse::RelationAction.new(field, objects: collection.removals, polarity: false) end end # merge all additions and removals into one large hash additions = additions.reduce({}) { |m, v| m.merge! v.as_json } removals = removals.reduce({}) { |m, v| m.merge! v.as_json } [additions, removals] end |