Class: Parse::Constraint::MatchesKeyInQueryConstraint
- Inherits:
-
Constraint
- Object
- 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 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.
Instance Method Details
#build ⇒ Hash
Returns the compiled constraint.
2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 |
# File 'lib/parse/query/constraints.rb', line 2215 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
2210 |
# File 'lib/parse/query/constraints.rb', line 2210 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 2200
|