Class: Parse::Constraint::DoesNotMatchKeyInQueryConstraint

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

Overview

Equivalent to the ‘$dontSelect` Parse query operation but for key matching. This matches objects where a field’s value does NOT equal another field’s value from a different query. This is the inverse of the MatchesKeyInQueryConstraint.

# Find users where user.company does NOT equal customer.company
customer_query = Customer.where(:active => true)
user_query = User.where(:company.does_not_match_key => { key: "company", query: customer_query })

# If the local field has the same name as the remote field, you can omit the key
# assumes key: 'company'
user_query = User.where(:company.does_not_match_key => customer_query)

Instance Attribute Summary

Attributes inherited from Parse::Constraint

#operand, #operation, #operator, #value

Instance Method Summary collapse

Methods inherited from Parse::Constraint

#as_json, constraint_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.



2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
# File 'lib/parse/query/constraints.rb', line 2264

def build
  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}.does_not_match_key_in_query => #{@value}"
    end
    query = query.compile(encode: false, includeClassName: true)
  elsif @value.is_a?(Parse::Query)
    # if its a query, then assume key is the same name as operand.
    query = @value.compile(encode: false, includeClassName: true)
  else
    raise ArgumentError, "Invalid `:does_not_match_key_in_query` query constraint. It should follow the format: :field.does_not_match_key_in_query => { key: 'key', query: '<Parse::Query>' }"
  end

  { @operation.operand => { :$dontSelect => { key: remote_field_name, query: query } } }
end

#does_not_match_keyDoesNotMatchKeyInQueryConstraint



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

constraint_keyword :$dontSelect

#does_not_match_key_in_queryDoesNotMatchKeyInQueryConstraint

A registered method on a symbol to create the constraint.

Examples:

q.where :field.does_not_match_key_in_query => { key: "remote_field", query: query }
q.where :field.does_not_match_key_in_query => query # assumes same field name

Returns:



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