From 5090f040565549d6110e5730fd864a986a99924d Mon Sep 17 00:00:00 2001 From: Alex Standiford Date: Tue, 26 May 2026 13:26:28 -0400 Subject: [PATCH] fix(clause-builder): drop predicate when field isn't on the active table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/Builders/MySqlClauseBuilder.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Builders/MySqlClauseBuilder.php b/lib/Builders/MySqlClauseBuilder.php index c19a47a..9dd45a9 100644 --- a/lib/Builders/MySqlClauseBuilder.php +++ b/lib/Builders/MySqlClauseBuilder.php @@ -125,10 +125,17 @@ protected function addCondition($field, string $operator, array $values, ?string return $this; } - $placeholder = $this->generatePlaceholder($field, $values, $operator); - $fieldStr = $this->getFieldString($field); + // If the field isn't on the active table, drop the whole predicate. + // Otherwise we'd push `null` for the field but still emit the operator + // and placeholder, producing invalid SQL like `WHERE = 'value'`. + if ($fieldStr === null) { + return $this; + } + + $placeholder = $this->generatePlaceholder($field, $values, $operator); + if (!empty($this->clauses) && $logic && in_array(strtoupper($logic), ['AND', 'OR'])) { $this->clauses[] = strtoupper($logic); }