Class: Parse::Constraint::ContainedInConstraint

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

Overview

Equivalent to the $in Parse query operation. Checks whether the value in the column field is contained in the set of values in the target array. If the field is an array data type, it checks whether at least one value in the field array is contained in the set of values in the target array. q.where :field.in => array q.where :score.in => [1,3,5,7,9]

Instance Method Summary collapse

Instance Method Details

#any ⇒ ContainedInConstraint

Alias for #in Alias for #in - more readable when checking if array contains any of the values

Examples:

q.where :tags.any => ["rock", "pop"]  # has at least one of these tags

Returns:



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

constraint_keyword :$in

#build ⇒ Hash

Returns the compiled constraint.

Returns:

  • (Hash) —

    the compiled constraint.



1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
# File 'lib/parse/query/constraints.rb', line 1138

def build
  val = list_value

  # Convert Parse objects to pointers for array contains queries
  if val.is_a?(Array)
    val = val.map do |item|
      item.respond_to?(:pointer) ? item.pointer : item
    end
  end

  { @operation.operand => { key => val } }
end

#contained_in ⇒ ContainedInConstraint

Alias for #in Alias for #in - more readable when checking if array contains any of the values

Examples:

q.where :tags.any => ["rock", "pop"]  # has at least one of these tags

Returns:



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

constraint_keyword :$in

#in ⇒ ContainedInConstraint

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

Examples:

q.where :field.in => array

Returns:



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