Skip to content

Commit

Permalink
Fix:fix bug whereDoesntHave db
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-fathi committed Sep 3, 2024
1 parent ec910be commit 4ae0f2f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/QueryFilter/Queries/DB/WhereDoesntHave.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use eloquentFilter\QueryFilter\Queries\BaseClause;
use Illuminate\Database\Query\Expression as Raw;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

/**
*
Expand All @@ -17,14 +18,14 @@ class WhereDoesntHave extends BaseClause
*/
public function apply($query)
{
$foreignKey = $this->values . '.id';

$from = $query->from;
$tableJoin = Str::singular($this->values);
$foreignKey = sprintf('"%s"."%s_id"', $from, $tableJoin);

$key_from = sprintf('"%s"."category_id"',$from);
$key = $this->values . '.id';

return $query->from($from)->whereNotExists(function ($q) use ($foreignKey, $from,$key_from) {
$q->select(DB::raw(1))->from($this->values)->where($foreignKey, '=', new Raw($key_from));
return $query->from($from)->whereNotExists(function ($q) use ($foreignKey, $from, $key) {
$q->select(DB::raw(1))->from($this->values)->where($key, '=', new Raw($foreignKey));
});
}
}

0 comments on commit 4ae0f2f

Please sign in to comment.