Skip to content

Commit b0661f1

Browse files
committed
Make deleted value configurable for SoftDeleteableFilter.php
1 parent ade7387 commit b0661f1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Mapping/Annotation/SoftDeleteable.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ final class SoftDeleteable implements GedmoAnnotation
3535

3636
public bool $hardDelete = true;
3737

38+
public $deletedValue = null;
39+
3840
/**
3941
* @param array<string, mixed> $data
4042
*/
41-
public function __construct(array $data = [], string $fieldName = 'deletedAt', bool $timeAware = false, bool $hardDelete = true)
43+
public function __construct(array $data = [], string $fieldName = 'deletedAt', bool $timeAware = false, bool $hardDelete = true, $deletedValue = null)
4244
{
4345
if ([] !== $data) {
4446
Deprecation::trigger(
@@ -53,12 +55,14 @@ public function __construct(array $data = [], string $fieldName = 'deletedAt', b
5355
$this->fieldName = $this->getAttributeValue($data, 'fieldName', $args, 1, $fieldName);
5456
$this->timeAware = $this->getAttributeValue($data, 'timeAware', $args, 2, $timeAware);
5557
$this->hardDelete = $this->getAttributeValue($data, 'hardDelete', $args, 3, $hardDelete);
58+
$this->deletedValue = $this->getAttributeValue($data, 'deletedValue', $args, 4, $deletedValue);
5659

5760
return;
5861
}
5962

6063
$this->fieldName = $fieldName;
6164
$this->timeAware = $timeAware;
6265
$this->hardDelete = $hardDelete;
66+
$this->deletedValue = $deletedValue;
6367
}
6468
}

src/SoftDeleteable/Filter/SoftDeleteableFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAli
7070

7171
$column = $quoteStrategy->getColumnName($config['fieldName'], $targetEntity, $platform);
7272

73-
$addCondSql = $targetTableAlias.'.'.$column.' IS NULL';
73+
$addCondSql = $targetTableAlias.'.'.$column.' '.$config['deletedValue'] === null ? 'IS NULL' : '= ' . $config['deletedValue'];
7474
if (isset($config['timeAware']) && $config['timeAware']) {
7575
$addCondSql = "({$addCondSql} OR {$targetTableAlias}.{$column} > {$platform->getCurrentTimestampSQL()})";
7676
}

0 commit comments

Comments
 (0)