Skip to content

Commit

Permalink
for SQL too
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Nov 23, 2024
1 parent 776205f commit e854ec9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
14 changes: 3 additions & 11 deletions src/Persistence/Sql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,19 +596,11 @@ protected function _subrenderCondition(array $row): string
}

if ($operator === null) {

Check failure on line 598 in src/Persistence/Sql/Query.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Ignored error pattern ~^(Undefined variable: \$(operator|value)|Variable \$value might not be defined\.)$~ (variable.undefined) in path /__w/data/data/src/Persistence/Sql/Query.php is expected to occur 3 times, but occurred only 2 times.

Check failure on line 598 in src/Persistence/Sql/Query.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Ignored error pattern ~^(Undefined variable: \$(operator|value)|Variable \$value might not be defined\.)$~ (variable.undefined) in path /__w/data/data/src/Persistence/Sql/Query.php is expected to occur 3 times, but occurred only 2 times.
if ($value instanceof Expressionable) {
$value = $value->getDsqlExpression($this);
}

if ($value instanceof self && $value->mode === 'select') {
$operator = 'in';
} else {
$operator = '=';
}
} else {
$operator = strtolower($operator);
$operator = '=';
}

$operator = strtolower($operator);

if (!in_array($operator, $this->supportedOperators, true)) {
throw (new Exception('Unsupported operator'))
->addMoreInfo('operator', $operator);
Expand Down
1 change: 1 addition & 0 deletions src/Reference/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function ref(Model $ourModelOrEntity, array $defaults = []): Model

return $this->createTheirModel($defaults)->addCondition(
$this->getTheirFieldName(),
$ourModelOrEntity->isEntity() ? '=' : 'in',
$this->getOurFieldValueForRefCondition($ourModelOrEntity)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Reference/HasOneSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function ref(Model $ourModelOrEntity, array $defaults = []): Model
$ourFieldExpression = $ourModelOrEntity->action('field', [$this->getOurField()]);

$theirModel->getModel(true)
->addCondition($this->getTheirFieldName($theirModel), $ourFieldExpression);
->addCondition($this->getTheirFieldName($theirModel), 'in', $ourFieldExpression);
}

return $theirModel;
Expand Down
2 changes: 1 addition & 1 deletion tests/Persistence/Sql/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public function testWhereBasic(): void
$this->q('[where]')->where('id', 'in', [1, 2])->render()[0]
);
self::assertSame(
'where "id" in (select * from "user")',
'where "id" = (select * from "user")',
$this->q('[where]')->where('id', $this->q()->table('user'))->render()[0]
);

Expand Down

0 comments on commit e854ec9

Please sign in to comment.