Class: Parse::Constraint::SelectionConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- Parse::Constraint::SelectionConstraint
- 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
-
#build ⇒ Hash
The compiled constraint.
-
#select ⇒ SelectionConstraint
A registered method on a symbol to create the constraint.
Instance Method Details
#build ⇒ Hash
Returns the compiled constraint.
2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 |
# File 'lib/parse/query/constraints.rb', line 2293 def build # if it's a hash, then it should be {:key=>"objectId", :query=>[]} remote_field_name = @operation.operand 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_subquery elsif @value.is_a?(Parse::Query) # if its a query, then assume dontSelect key is the same name as operand. query = @value.compile_subquery 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 |
#select ⇒ SelectionConstraint
A registered method on a symbol to create the constraint. Maps to Parse operator "$select".
2289 |
# File 'lib/parse/query/constraints.rb', line 2289 constraint_keyword :$select |