Document how the Stache treats a missing field in where queries - #2002
Open
joshdaugherty wants to merge 1 commit into
Open
joshdaugherty wants to merge 1 commit into
joshdaugherty wants to merge 1 commit into
Conversation
On the flat-file driver an entry without a field resolves that field to null, so whereNull matches it and where('field', false) matches missing, null, false and empty-string values alike.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016o2kMZ4DZaNGJ4pUqPov7D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Content Queries page does not say what
whereNull,whereNotNullandwheredo when an entry has no value at all for the field being queried. On the flat-file driver the answer is not obvious, and it matters most for toggle fields, where a missing key usually means "never set".This adds a short note to the
WhereNullsection, scoped to the Stache.Measured on statamic/cms v6.26.0 against entries holding a missing key,
null,false,true,''and a non-empty string:whereNullnullwhereNotNullfalse,true,'', non-empty stringwhere(field, false)andwhere(field, '')null,false,''where(field, true)trueonlywhere(field, '!=', false)null,true, non-empty stringThe cause is in the Stache query builder: every entry's value is resolved before filtering, so a missing key becomes
null.filterWhereNulltests=== null, andfilterTestEqualscomparesstrtolower($item ?? '')withstrtolower($value ?? ''), which foldsnull,falseand''together.