Class: Parse::Constraint::ExistsConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/parse/query/constraints.rb

Overview

Equivalent to the #exists Parse query operation. Checks whether a value is set for key. The difference between this operation and the nullability check is when using compound queries with location. q.where :field.exists => true

Instance Method Summary collapse

Instance Method Details

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.



330
331
332
333
334
335
336
337
338
339
# File 'lib/parse/query/constraints.rb', line 330

def build
  # if nullability is equal true, then $exists should be set to false
  value = formatted_value

  unless value == true || value == false
    raise ArgumentError, "#{self.class}: Non-Boolean value passed, it must be either `true` or `false`"
  end

  return { @operation.operand => { key => value } }
end

#existsExistsConstraint

A registered method on a symbol to create the constraint. Maps to Parse operator "$exists".

Examples:

q.where :field.exists => true

Returns:



326
# File 'lib/parse/query/constraints.rb', line 326

constraint_keyword :$exists