Class: Parse::Constraint::SelectionConstraint

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

Overview

Equivalent to the $select Parse query operation. This matches a value for a key in the result of a different query. q.where :field.select => { key: "field", query: query }

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

# if the local field is the same name as the foreign table field, you can omit hash # assumes key: 'city' q.where :city.select => 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, 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.



1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
# File 'lib/parse/query/constraints.rb', line 1560

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 `:select` query constraint. It should follow the format: :field.select => { key: 'key', query: '<Parse::Query>' }"
  end
  { @operation.operand => { :$select => { key: remote_field_name, query: query } } }
end

#selectSelectionConstraint

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

Returns:



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

constraint_keyword :$select