-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8e577d
commit 9a68bbc
Showing
6 changed files
with
104 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,14 @@ public function createSchema() | |
$table->timestamps(); | ||
$table->softDeletes(); | ||
}); | ||
|
||
$this->schema()->create('comments', function ($table) { | ||
$table->increments('id'); | ||
$table->integer('post_id'); | ||
$table->string('body'); | ||
$table->timestamps(); | ||
$table->softDeletes(); | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -54,6 +62,8 @@ public function createSchema() | |
public function tearDown() | ||
{ | ||
$this->schema()->drop('users'); | ||
$this->schema()->drop('posts'); | ||
$this->schema()->drop('comments'); | ||
} | ||
|
||
/** | ||
|
@@ -137,11 +147,55 @@ public function testWhereHasWithDeletedRelationship() | |
|
||
$abigail = SoftDeletesTestUser::where('email', '[email protected]')->first(); | ||
$post = $abigail->posts()->create(['title' => 'First Title']); | ||
$post->delete(); | ||
|
||
$users = SoftDeletesTestUser::where('email', '[email protected]')->has('posts')->get(); | ||
$this->assertEquals(0, count($users)); | ||
|
||
$users = SoftDeletesTestUser::where('email', '[email protected]')->has('posts')->get(); | ||
$this->assertEquals(1, count($users)); | ||
|
||
$users = SoftDeletesTestUser::where('email', '[email protected]')->orHas('posts')->get(); | ||
$this->assertEquals(1, count($users)); | ||
|
||
$users = SoftDeletesTestUser::whereHas('posts', function ($query) { | ||
$query->where('title', 'First Title'); | ||
})->get(); | ||
$this->assertEquals(1, count($users)); | ||
|
||
$users = SoftDeletesTestUser::whereHas('posts', function ($query) { | ||
$query->where('title', 'Another Title'); | ||
})->get(); | ||
$this->assertEquals(0, count($users)); | ||
|
||
$users = SoftDeletesTestUser::where('email', '[email protected]')->orWhereHas('posts', function ($query) { | ||
$query->where('title', 'First Title'); | ||
})->get(); | ||
$this->assertEquals(1, count($users)); | ||
|
||
// With Post Deleted... | ||
|
||
$post->delete(); | ||
$users = SoftDeletesTestUser::has('posts')->get(); | ||
$this->assertEquals(0, count($users)); | ||
} | ||
|
||
/** | ||
* @group test | ||
*/ | ||
public function testWhereHasWithNestedDeletedRelationship() | ||
{ | ||
$this->createUsers(); | ||
|
||
$abigail = SoftDeletesTestUser::where('email', '[email protected]')->first(); | ||
$post = $abigail->posts()->create(['title' => 'First Title']); | ||
$comment = $post->comments()->create(['body' => 'Comment Body']); | ||
$comment->delete(); | ||
|
||
$users = SoftDeletesTestUser::has('posts.comments')->get(); | ||
$this->assertEquals(0, count($users)); | ||
|
||
$users = SoftDeletesTestUser::doesntHave('posts.comments')->get(); | ||
$this->assertEquals(1, count($users)); | ||
} | ||
|
||
/** | ||
|
@@ -203,4 +257,22 @@ class SoftDeletesTestPost extends Eloquent | |
protected $dates = ['deleted_at']; | ||
protected $table = 'posts'; | ||
protected $guarded = []; | ||
|
||
public function comments() | ||
{ | ||
return $this->hasMany(SoftDeletesTestComment::class, 'post_id'); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Eloquent Models... | ||
*/ | ||
class SoftDeletesTestComment extends Eloquent | ||
{ | ||
use SoftDeletes; | ||
|
||
protected $dates = ['deleted_at']; | ||
protected $table = 'comments'; | ||
protected $guarded = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters