Class: Parse::RelationAction
- Inherits:
- Object
- Object
- Parse::RelationAction
- Defined in:
- lib/parse/model/core/actions.rb
Overview
A Parse::RelationAction is special operation that adds one object to a relational table as to another. Depending on the polarity of the action, the objects are either added or removed from the relation. This class is used to generate the proper hash request formats Parse needs in order to modify relational information for classes.
Instance Attribute Summary collapse
Instance Method Summary collapse
- #as_json(*args) ⇒ Hash
A hash representing a relation operation.
- #initialize(field, polarity: true, objects: []) ⇒ RelationAction constructor
A new instance of RelationAction.
Constructor Details
#initialize(field, polarity: true, objects: []) ⇒ RelationAction
Returns a new instance of RelationAction.
71 72 73 74 75 | # File 'lib/parse/model/core/actions.rb', line 71 def initialize(field, polarity: true, objects: []) @key = field.to_s self.polarity = polarity @objects = Array.wrap(objects).compact end |
Instance Attribute Details
#key ⇒ Boolean, ...
66 | # File 'lib/parse/model/core/actions.rb', line 66 attr_accessor :polarity, :key, :objects |
#objects ⇒ Boolean, ...
66 | # File 'lib/parse/model/core/actions.rb', line 66 attr_accessor :polarity, :key, :objects |
#polarity ⇒ Boolean, ...
66 67 68 | # File 'lib/parse/model/core/actions.rb', line 66 def polarity @polarity end |
Instance Method Details
#as_json(*args) ⇒ Hash
Returns a hash representing a relation operation.
78 79 80 81 82 83 | # File 'lib/parse/model/core/actions.rb', line 78 def as_json(*args) { @key => { "__op" => (@polarity == true ? ADD : REMOVE), "objects" => objects.parse_pointers, } }.as_json end |