Skip to content

Commit 0d05a5d

Browse files
committed
FIX ConditionList->not() missing in RelationalExpression
1 parent 6738511 commit 0d05a5d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Driver/QueryCompiler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ protected function compileComparison(ComparisonOperationInterface $expr): string
348348

349349
protected function compileRelationalExpression(RelationalExpression $expr): string
350350
{
351-
$output = $this->compileComparable($expr->getOperand1());
351+
$output = $expr->isNegated() ? 'NOT ' : '';
352+
$output .= $this->compileComparable($expr->getOperand1());
352353
$output .= $this->compileRelationalOperator($expr->getOperator());
353354
$output .= $this->compileComparable($expr->getOperand2());
354355
return $output;

src/Expressions/Comparison/RelationalExpression.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Francerz\SqlBuilder\Expressions\Comparison;
44

55
use Francerz\SqlBuilder\Expressions\ComparableComponentInterface;
6+
use Francerz\SqlBuilder\Expressions\NegatableInterface;
67
use Francerz\SqlBuilder\Expressions\TwoOperandsInterface;
78
use Francerz\SqlBuilder\Nesting\NestOperationResolverInterface;
89
use Francerz\SqlBuilder\Nesting\NestTranslator;
@@ -14,13 +15,16 @@
1415
class RelationalExpression implements
1516
ComparisonOperationInterface,
1617
TwoOperandsInterface,
18+
NegatableInterface,
1719
NestOperationResolverInterface
1820
{
1921

2022
private $operand1;
2123
private $operand2;
2224
private $operator;
2325

26+
private $negated = false;
27+
2428
public function __construct(
2529
ComparableComponentInterface $operand1,
2630
ComparableComponentInterface $operand2,
@@ -66,6 +70,16 @@ public function getOperator()
6670
return $this->operator;
6771
}
6872

73+
public function negate(bool $negate = true)
74+
{
75+
$this->negated = $negate;
76+
}
77+
78+
public function isNegated(): bool
79+
{
80+
return $this->negated;
81+
}
82+
6983
public function requiresTransform(): bool
7084
{
7185
return $this->operand1 instanceof ValueProxy || $this->operand2 instanceof ValueProxy;

test/SelectQueryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,15 @@ public function testWhereArgs()
157157

158158
$this->assertEquals($expected, $compiled->getQuery());
159159
}
160+
161+
public function testWhereNot()
162+
{
163+
$query = Query::selectFrom(['groups']);
164+
$query->where()->not('group_id', 1);
165+
166+
$compiled = $this->compiler->compileSelect($query);
167+
168+
$expected = "SELECT groups.* FROM groups WHERE NOT group_id = :v1";
169+
$this->assertEquals($expected, $compiled->getQuery());
170+
}
160171
}

0 commit comments

Comments
 (0)