Class: Parse::Constraint::ContainedByConstraint

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

Overview

Equivalent to the $containedBy Parse query operation. Matches documents where the array field's values are all within the supplied set (the inverse of ContainsAllConstraint: the field must be a subset of the provided array). The field column should be of type Array in your Parse class.

q.where :field.contained_by => [1, 2, 3] q.where :tags.contained_by => ["ruby", "rails", "parse"]

Instance Attribute Summary

Attributes inherited from Parse::Constraint

#operand, #operation, #operator, #value

Instance Method Summary collapse

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

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.



524
525
526
527
528
# File 'lib/parse/query/constraints.rb', line 524

def build
  val = formatted_value
  val = [val].compact unless val.is_a?(Array)
  { @operation.operand => { key => val } }
end

#contained_byContainedByConstraint

A registered method on a symbol to create the constraint. Maps to Parse operator "$containedBy".

Examples:

q.where :tags.contained_by => ["ruby", "rails"]

Returns:



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

constraint_keyword :$containedBy