Class: Parse::Constraint::RelationQueryConstraint

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

Overview

Equivalent to the `$relatedTo` Parse query operation. If you want to retrieve objects that are members of a `Relation` field in your Parse class.

q.where :field.related_to => pointer

# find all Users who have liked this post object
post = Post.first
users = Parse::User.all :likes.related_to => post

Instance Attribute Summary

Attributes inherited from Parse::Constraint

#operand, #operation, #operator, #value

Instance Method Summary collapse

Methods inherited from Parse::Constraint

#as_json, contraint_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.


536
537
538
539
540
541
542
# File 'lib/parse/query/constraints.rb', line 536

def build
  # pointer = formatted_value
  # unless pointer.is_a?(Parse::Pointer)
  #   raise "Invalid Parse::Pointer passed to :related(#{@operation.operand}) constraint : #{pointer}"
  # end
  { :$relatedTo => { object: formatted_value, key: @operation.operand } }
end

#relRelationQueryConstraint

Alias for #related_to


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

contraint_keyword :$relatedTo

A registered method on a symbol to create the constraint. Maps to Parse operator “$relatedTo”.

Examples:

q.where :field.related_to => pointer

Returns:


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