Skip to content

Document how the Stache treats a missing field in where queries - #2002

Open
joshdaugherty wants to merge 1 commit into
statamic:6.xfrom
joshdaugherty:docs/where-missing-field-values
Open

joshdaugherty wants to merge 1 commit into
statamic:6.xfrom
joshdaugherty:docs/where-missing-field-values

Conversation

@joshdaugherty

Copy link
Copy Markdown

The Content Queries page does not say what whereNull, whereNotNull and where do 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 WhereNull section, 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:

Query Matches
whereNull missing key, null
whereNotNull false, true, '', non-empty string
where(field, false) and where(field, '') missing key, null, false, ''
where(field, true) true only
where(field, '!=', false) missing key, null, true, non-empty string

The cause is in the Stache query builder: every entry's value is resolved before filtering, so a missing key becomes null. filterWhereNull tests === null, and filterTestEquals compares strtolower($item ?? '') with strtolower($value ?? ''), which folds null, false and '' together.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant