Skip to content

Commit

Permalink
fix ambiguous calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Sep 23, 2021
1 parent d3bda91 commit 95b1c00
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions code/SoftDeleteSearchFilter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use SilverStripe\ORM\DataObjectSchema;
use SilverStripe\ORM\DataQuery;
use SilverStripe\ORM\Filters\SearchFilter;

Expand Down Expand Up @@ -28,10 +29,12 @@ protected function getOnlyDeleted()
protected function applyOne(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$schema = DataObjectSchema::singleton();
$tableName = $schema->tableName($this->model);

$query = $query->setQueryParam("SoftDeletable.filter", false);
if ($this->getOnlyDeleted() || $this->name == "OnlyDeleted") {
$query = $query->where("Deleted IS NOT NULL");
$query = $query->where("\"$tableName\".\"Deleted\" IS NOT NULL");
}

return $query;
Expand All @@ -40,10 +43,12 @@ protected function applyOne(DataQuery $query)
protected function applyMany(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$schema = DataObjectSchema::singleton();
$tableName = $schema->tableName($this->model);

$query = $query->setQueryParam("SoftDeletable.filter", false);
if ($this->getOnlyDeleted() || $this->name == "OnlyDeleted") {
$query = $query->where("Deleted IS NOT NULL");
$query = $query->where("\"$tableName\".\"Deleted\" IS NOT NULL");
}

return $query;
Expand All @@ -52,10 +57,12 @@ protected function applyMany(DataQuery $query)
protected function excludeOne(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$schema = DataObjectSchema::singleton();
$tableName = $schema->tableName($this->model);

$query = $query->setQueryParam("SoftDeletable.filter", true);
if ($this->getOnlyDeleted() || $this->name == "OnlyDeleted") {
$query = $query->where("Deleted IS NULL");
$query = $query->where("\"$tableName\".\"Deleted\" IS NULL");
}

return $query;
Expand All @@ -64,10 +71,12 @@ protected function excludeOne(DataQuery $query)
protected function excludeMany(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$schema = DataObjectSchema::singleton();
$tableName = $schema->tableName($this->model);

$query = $query->setQueryParam("SoftDeletable.filter", true);
if ($this->getOnlyDeleted() || $this->name == "OnlyDeleted") {
$query = $query->where("Deleted IS NULL");
$query = $query->where("\"$tableName\".\"Deleted\" IS NULL");
}

return $query;
Expand Down

0 comments on commit 95b1c00

Please sign in to comment.