Skip to content

Commit 1a037ee

Browse files
committed
Adds “empty” array query constraint
1 parent d99035d commit 1a037ee

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

Changes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Parse-Stack Changelog
22

3+
### 1.11.3
4+
- Adds "empty" query constraint option
5+
- Adds "include" alias for "includes" query method
6+
37
### 1.11.1
48
- Always applies attribute changes in first_or_create resource_attrs argument
59

lib/parse/query/constraints.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,32 @@ def build
288288
end
289289
end
290290

291+
# Checks whether an array field contains any elements
292+
# q.where :field.empty => true
293+
#
294+
# @see NullabilityConstraint
295+
class EmptyConstraint < Constraint
296+
# @!method empty
297+
# A registered method on a symbol to create the constraint.
298+
# @example
299+
# q.where :field.empty => true
300+
# @return [ExistsConstraint]
301+
contraint_keyword :$exists
302+
register :empty
303+
304+
# @return [Hash] the compiled constraint.
305+
def build
306+
# if nullability is equal true, then $empty should be set to false
307+
value = formatted_value
308+
309+
unless value == true || value == false
310+
raise ArgumentError, "#{self.class}: Non-Boolean value passed, it must be either `true` or `false`"
311+
end
312+
313+
return { "#{@operation.operand}.0" => { key => !value } }
314+
end
315+
end
316+
291317
# Equivalent to the `$in` Parse query operation. Checks whether the value in the
292318
# column field is contained in the set of values in the target array. If the
293319
# field is an array data type, it checks whether at least one value in the

lib/parse/stack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ module Parse
66
# The Parse Server SDK for Ruby
77
module Stack
88
# The current version.
9-
VERSION = "1.11.2"
9+
VERSION = "1.11.3"
1010
end
1111
end

0 commit comments

Comments
 (0)