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 f1ca317
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/Persistence/Sql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,7 @@ protected function _subrenderCondition(array $row): string
$value = $value->getDsqlExpression($this);
}

if ($value instanceof self && $value->mode === 'select') {
$operator = 'in';
} else {
$operator = '=';
}
$operator = '=';
} else {
$operator = strtolower($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 f1ca317

Please sign in to comment.