Skip to content

Commit

Permalink
fix(QueryBuilder): where(Closure) 生成的语句排除默认范围查询
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Nov 2, 2023
1 parent 9b743a1 commit 4255288
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/Db/QueryBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,8 @@ protected function addWhere(
'wei' => $this->wei,
'db' => $this->getDb(),
'table' => $this->getTable(),
// NOTE: Remove default scopes for model
'withoutScopes' => true,
]);
$column($query);
$column = $query;
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/Model/DefaultScopeTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ public function testUnscopeMulti()
public function testScopeWithClosure()
{
$scope = TestDefaultScope::where(function (TestDefaultScope $defaultScope) {
$defaultScope->unscoped();
$defaultScope->where('name', 'test');
});

$this->assertStringNotContainsString('(`active` = 1', $scope->getRawSql());

$this->assertStringContainsString(
"WHERE `active` = 1 AND `type` = 'A' AND (`name` = 'test')",
$scope->getRawSql()
Expand Down

0 comments on commit 4255288

Please sign in to comment.