Class: Parse::Constraint::MatchesKeyInQueryConstraint
- Inherits:
-
Parse::Constraint
- Object
- Parse::Constraint
- Parse::Constraint::MatchesKeyInQueryConstraint
- Defined in:
- lib/parse/query/constraints.rb
Overview
Equivalent to the ‘$select` Parse query operation but for key matching. This matches objects where a field’s value equals another field’s value from a different query. Useful for performing join-like operations where fields from different classes match.
# Find users where user.company equals customer.company
customer_query = Customer.where(:active => true)
user_query = User.where(:company.matches_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.matches_key => customer_query)
Instance Attribute Summary
Attributes inherited from Parse::Constraint
#operand, #operation, #operator, #value
Instance Method Summary collapse
-
#build ⇒ Hash
The compiled constraint.
-
#matches_key ⇒ MatchesKeyInQueryConstraint
Alias for #matches_key_in_query.
-
#matches_key_in_query ⇒ MatchesKeyInQueryConstraint
A registered method on a symbol to create the constraint.
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
#build ⇒ Hash
Returns the compiled constraint.
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 |
# File 'lib/parse/query/constraints.rb', line 2213 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}.matches_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 `:matches_key_in_query` query constraint. It should follow the format: :field.matches_key_in_query => { key: 'key', query: '<Parse::Query>' }" end { @operation.operand => { :$select => { key: remote_field_name, query: query } } } end |
#matches_key ⇒ MatchesKeyInQueryConstraint
Alias for #matches_key_in_query
2208 |
# File 'lib/parse/query/constraints.rb', line 2208 constraint_keyword :$select |
#matches_key_in_query ⇒ MatchesKeyInQueryConstraint
A registered method on a symbol to create the constraint.
|
|
# File 'lib/parse/query/constraints.rb', line 2198
|