Class: Parse::Constraint::ExistsConstraint

Inherits:
Parse::Constraint 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 Attribute Summary

Attributes inherited from Parse::Constraint

#operand, #operation, #operator, #value

Instance Method Summary collapse

Methods inherited from Parse::Constraint

#as_json, contraint_keyword, create, #formatted_value, formatted_value, #initialize, #key, #precedence, register, #to_s

Constructor Details

This class inherits a constructor from Parse::Constraint

Instance Method Details

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.


281
282
283
284
285
286
287
288
289
290
# File 'lib/parse/query/constraints.rb', line 281

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:


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

contraint_keyword