Skip to content

Commit

Permalink
don't use filtersOnID
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Mar 20, 2023
1 parent 047694a commit e4a208a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions code/SoftDeletable.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,22 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
if ($dataQuery->getQueryParam('SoftDeletable.filter') === false) {
return;
}
// Don't run if querying by ID
if ($query->filtersOnID() && self::config()->check_filters_on_id) {
return;
}

$froms = $query->getFrom();
$froms = array_keys($froms);
$tableName = array_shift($froms);

// Don't run if querying by ID on base table because it's much more convenient
// Don't use filtersOnID as it will return true when filtering a relation by ID as well
if (self::config()->check_filters_on_id) {
foreach ($query->getWhereParameterised($parameters) as $predicate) {
$filtered = str_replace(['"', '`', ' ', 'IN'], ['', '', '', '='], $predicate);
// Where must contain a clause with Table.ID = or Table.ID IN

This comment has been minimized.

Copy link
@michalkleiner

michalkleiner Mar 20, 2023

@lekoala "must contain" is represented via strpos as !== false whereas "Starts with" is represented by === 0, so either the comment or the code is inaccurate.

This comment has been minimized.

Copy link
@lekoala

lekoala Mar 20, 2023

Author Owner

@michalkleiner === 0 is what i want here (= Starts with), because if the where clause is Table.ID = or Table.ID IN, i don't want softdelete behaviour applied.

if (strpos($filtered, $tableName . ".ID=") === 0) {
return;
}
}
}
$query->addWhere("\"$tableName\".\"Deleted\" IS NULL");
}

Expand Down

0 comments on commit e4a208a

Please sign in to comment.