Skip to content

Commit e4a208a

Browse files
committed
don't use filtersOnID
1 parent 047694a commit e4a208a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

code/SoftDeletable.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,22 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
103103
if ($dataQuery->getQueryParam('SoftDeletable.filter') === false) {
104104
return;
105105
}
106-
// Don't run if querying by ID
107-
if ($query->filtersOnID() && self::config()->check_filters_on_id) {
108-
return;
109-
}
110106

111107
$froms = $query->getFrom();
112108
$froms = array_keys($froms);
113109
$tableName = array_shift($froms);
110+
111+
// Don't run if querying by ID on base table because it's much more convenient
112+
// Don't use filtersOnID as it will return true when filtering a relation by ID as well
113+
if (self::config()->check_filters_on_id) {
114+
foreach ($query->getWhereParameterised($parameters) as $predicate) {
115+
$filtered = str_replace(['"', '`', ' ', 'IN'], ['', '', '', '='], $predicate);
116+
// Where must contain a clause with Table.ID = or Table.ID IN
117+
if (strpos($filtered, $tableName . ".ID=") === 0) {
118+
return;
119+
}
120+
}
121+
}
114122
$query->addWhere("\"$tableName\".\"Deleted\" IS NULL");
115123
}
116124

0 commit comments

Comments
 (0)