Class: Parse::Constraint::NullabilityConstraint

Inherits:
Constraint
  • Object
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 Method Summary collapse

Instance Method Details

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/parse/query/constraints.rb', line 296

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:



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

constraint_keyword :$exists