Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function getBaseQuery()
*/
public function toBase()
{
return $this->query->getQuery();
return $this->query->applyScopes()->getQuery();
}

/**
Expand Down
19 changes: 18 additions & 1 deletion tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ public function testSoftDeletesAreNotRetrievedFromBaseQuery()
$this->assertCount(1, $query->get());
}

public function testSoftDeletesAreNotRetrievedFromRelationshipBaseQuery()
{
[, $abigail] = $this->createUsers();

$abigail->posts()->create(['title' => 'Foo']);
$abigail->posts()->create(['title' => 'Bar'])->delete();

$query = $abigail->posts()->toBase();

$this->assertInstanceOf(Builder::class, $query);
$this->assertCount(1, $query->get());
}

public function testSoftDeletesAreNotRetrievedFromBuilderHelpers()
{
$this->createUsers();
Expand Down Expand Up @@ -867,13 +880,17 @@ public function testMorphToNonSoftDeletingModel()

/**
* Helpers...
*
* @return \Illuminate\Tests\Database\SoftDeletesTestUser[]
*/
protected function createUsers()
{
$taylor = SoftDeletesTestUser::create(['id' => 1, 'email' => '[email protected]']);
SoftDeletesTestUser::create(['id' => 2, 'email' => '[email protected]']);
$abigail = SoftDeletesTestUser::create(['id' => 2, 'email' => '[email protected]']);

$taylor->delete();

return [$taylor, $abigail];
}

/**
Expand Down