From 47e3d2fb243ce9f7b99630b03d2cba3d93881b39 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 13 Nov 2024 07:59:22 +0000 Subject: [PATCH] Update docs for whereJsonOverlaps and correct behaviour of whereJsonContains --- content/collections/docs/content-queries.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/content/collections/docs/content-queries.md b/content/collections/docs/content-queries.md index 0a6f87f66..f432cd003 100644 --- a/content/collections/docs/content-queries.md +++ b/content/collections/docs/content-queries.md @@ -310,7 +310,7 @@ Entry::query() ->get(); ``` -Or can pass an array of values. This will match if any of the values are found in the field. +Or can pass an array of values. This will match if **all** of the values are found in the field. ```php Entry::query() @@ -318,12 +318,24 @@ Entry::query() ->get(); ``` -You can use `whereJsonDoesntContain()` to query the absence of a value or values in a JSON array: +If you want to check for **any** value being present, use whereJsonOverlaps. + +```php +Entry::query() + ->whereJsonOverlaps('my_array_field->sub_field', ['statamic', 'is', 'rad']) // [tl! ~~] + ->get(); +``` + +You can use `whereJsonDoesntContain()` and `whereJsonDoesntOverlap()` to query the absence of a value or values in a JSON array: ```php Entry::query() ->whereJsonDoesntContain('my_array_field->sub_field', 'statamic') // [tl! ~~] ->get(); + +Entry::query() + ->whereJsonDoesntOverlap('my_array_field->sub_field', 'statamic') // [tl! ~~] + ->get(); ``` You can use whereJsonLength method to query JSON arrays by their length: