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); }