Skip to content

fix(clause-builder): drop predicate when field isn't on the active table#13

Merged
alexstandiford merged 1 commit into
mainfrom
fix/clause-builder-unknown-field
May 26, 2026
Merged

fix(clause-builder): drop predicate when field isn't on the active table#13
alexstandiford merged 1 commit into
mainfrom
fix/clause-builder-unknown-field

Conversation

@alexstandiford

Copy link
Copy Markdown
Contributor

Summary

addCondition() calls getFieldString(), which returns null for any field not declared on the bound table — a legitimate filter to drop unknown fields silently. But the rest of addCondition still pushes the operator and placeholder onto the clauses array regardless, producing invalid SQL like `WHERE = 'value'` (or `WHERE AND = 'value'` when chained).

This skips the entire predicate when `fieldStr` is null, which matches the apparent intent of `getFieldString` returning null in the first place.

Why this matters

Caught while porting the clause builder to `phpnomad/sqlite-integration`. Wrote a test asserting that unknown fields silently no-op the predicate; instead the test produced a SQL syntax error from the engine. The SQLite port carries the same fix.

Test plan

  • Existing test suite continues to pass
  • A new test in this repo (parallel to the SQLite one) that calls `->where('not_a_field', '=', 'x')` and confirms the query is a no-op rather than producing invalid SQL

The fix is one branch — no behavior change for valid fields, only fixes the broken silent-filter path.

addCondition() calls getFieldString() which returns null for any field
not declared on the bound table — a legitimate filter to drop unknown
fields silently. But the rest of addCondition still pushed the operator
and placeholder onto the clauses array regardless, producing invalid SQL
like `WHERE = 'value'` (or `WHERE AND = 'value'` chained).

Skip the entire predicate when fieldStr is null, matching the apparent
intent of getFieldString returning null in the first place.

Caught while porting the clause builder to phpnomad/sqlite-integration —
the SQLite port carries the same fix.
@alexstandiford alexstandiford force-pushed the fix/clause-builder-unknown-field branch from 1fb13d9 to 5090f04 Compare May 26, 2026 18:01
@alexstandiford alexstandiford merged commit fdd9080 into main May 26, 2026
8 checks passed
@alexstandiford alexstandiford deleted the fix/clause-builder-unknown-field branch May 26, 2026 18:18
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