Skip to content

Commit

Permalink
Check inner join with alias for soft deletes
Browse files Browse the repository at this point in the history
byjg committed Nov 11, 2024
1 parent 6d6c020 commit 3d9238b
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/WhereTrait.php
Original file line number Diff line number Diff line change
@@ -44,9 +44,14 @@ protected function getWhere(): ?array
/** @psalm-suppress RedundantCondition This is a Trait, and $this->join is defined elsewhere */
if (isset($this->join)) {
foreach ($this->join as $item) {
if (!($item['table'] instanceof QueryBasic) && !in_array($item['table'], $tableList) && ORM::getMapper($item['table'])?->isSoftDeleteEnabled() === true) {
$tableList[] = $item['table'];
$where[] = ["filter" => "{$item['table']}.deleted_at is null", "params" => []];
if ($item['table'] instanceof QueryBasic) {
continue;
}

$tableName = $item["alias"] ?? $item['table'];
if (!in_array($tableName, $tableList) && ORM::getMapper($item['table'])?->isSoftDeleteEnabled() === true) {
$tableList[] = $tableName;
$where[] = ["filter" => "{$tableName}.deleted_at is null", "params" => []];
}
}
}
2 changes: 1 addition & 1 deletion tests/RepositoryTest.php
Original file line number Diff line number Diff line change
@@ -1261,7 +1261,7 @@ public function testMappingAttributeInsert()
$this->assertNull($result[0]->getDeletedAt());

// Check if the updated_at works
sleep(2);
sleep(1);
$info->value = 99.5;
$infoRepository->save($info);
/** @var ModelWithAttributes[] $result2 */

0 comments on commit 3d9238b

Please sign in to comment.