Class: Parse::Constraint::RejectionConstraint

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

Overview

Equivalent to the `$dontSelect` Parse query operation. Requires that a field's value not match a value for a key in the result of a different query.

q.where :field.reject => { key: :other_field, query: query }

value = { key: 'city', query: Artist.where(:fan_count.gt => 50) }
q.where :hometown.reject => value

# if the local field is the same name as the foreign table field, you can omit hash
# assumes key: 'city'
q.where :city.reject => Artist.where(:fan_count.gt => 50)

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.



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/parse/query/constraints.rb', line 462

def build

  # if it's a hash, then it should be {:key=>"objectId", :query=>[]}
  remote_field_name = @operation.operand
  query = nil
  if @value.is_a?(Hash)
    res = @value.symbolize_keys
    remote_field_name = res[:key] || remote_field_name
    query = res[:query]
    unless query.is_a?(Parse::Query)
      raise ArgumentError, "Invalid Parse::Query object provided in :query field of value: #{@operation.operand}.#{$dontSelect} => #{@value}"
    end
    query = query.compile(encode: false, includeClassName: true)
  elsif @value.is_a?(Parse::Query)
    # if its a query, then assume dontSelect key is the same name as operand.
    query = @value.compile(encode: false, includeClassName: true)
  else
    raise ArgumentError, "Invalid `:reject` query constraint. It should follow the format: :field.reject => { key: 'key', query: '<Parse::Query>' }"
  end
  { @operation.operand => { :$dontSelect => { key: remote_field_name, query: query } } }
end

#dont_selectRejectionConstraint

A registered method on a symbol to create the constraint. Maps to Parse operator “$dontSelect”.

Examples:

q.where :field.reject => { key: :other_field, query: query }

Returns:

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

#rejectRejectionConstraint

Alias for #dont_select

Returns:



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

contraint_keyword :$dontSelect