Class: Parse::Constraint::NullabilityConstraint

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

Overview

Note:

Parse currently has a bug that if you select items near a location and want to make sure a different column has a value, you need to search where the column does not contanin a null/undefined value. Therefore we override the build method to change the operation to a NotEqualConstraint.

Provides a mechanism using the equality operator to check for `(undefined)` values. Nullabiliity constraint maps the `$exists` Parse clause to enable checking for existance in a column when performing geoqueries due to a Parse limitation.

q.where :field.null => false

See Also:

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.


246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/parse/query/constraints.rb', line 246

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

  if value == true
    return { @operation.operand => { key => false} }
  else
    #current bug in parse where if you want exists => true with geo queries
    # we should map it to a "not equal to null" constraint
    return { @operation.operand => { Parse::Constraint::NotEqualConstraint.key => nil } }
  end

end

#nullNullabilityConstraint

A registered method on a symbol to create the constraint.

Examples:

q.where :field.null => true

Returns:


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

contraint_keyword