Class: Parse::Constraint::SelectionConstraint

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

Instance Method Details

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.



1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
# File 'lib/parse/query/constraints.rb', line 1531

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:



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

constraint_keyword :$select