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

#build ⇒ Hash

Returns the compiled constraint.

Returns:

  • (Hash) —

    the compiled constraint.



1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
# File 'lib/parse/query/constraints.rb', line 1070

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

#exists ⇒ ExistsConstraint

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

Examples:

q.where :field.exists => true

Returns:



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

constraint_keyword :$exists