From 3f2165e10730343e8b7e7cbc3c642527c359d845 Mon Sep 17 00:00:00 2001 From: Iskandar Rafiev Date: Sat, 10 Mar 2018 00:28:56 -0500 Subject: [PATCH] Add a unit test for testing nested relationships with soft deleted records. --- tests/JoinerTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/JoinerTest.php b/tests/JoinerTest.php index 9d50f6d..503df53 100644 --- a/tests/JoinerTest.php +++ b/tests/JoinerTest.php @@ -2,6 +2,7 @@ namespace Sofa\Eloquence\Tests; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Query\Builder as Query; use Illuminate\Database\Query\Grammars\Grammar; use Illuminate\Database\Eloquent\Model; @@ -87,6 +88,23 @@ public function it_joins_relations_on_eloquent_builder() $this->assertEquals($sql, $query->toSql()); } + /** + * @test + */ + public function it_joins_nested_relations_with_soft_delete() + { + $sql = 'select * from "users" '. + 'inner join "posts" on "users"."id" = "posts"."user_id" and "posts"."deleted_at" is null '. + 'inner join "comments" on "posts"."id" = "comments"."post_id" '; + + $query = $this->getQuery(); + $joiner = $this->factory->make($query); + + $joiner->join('posts.comments'); + + $this->assertEquals($sql, $query->toSql()); + } + public function getQuery() { $model = new JoinerUserStub; @@ -155,7 +173,18 @@ class JoinerCompanyStub extends Model { } class JoinerPostStub extends Model { + use SoftDeletes; + protected $table = 'posts'; + + public function comments() + { + return $this->hasMany('Sofa\Eloquence\Tests\JoinerCommentStub', 'post_id'); + } +} + +class JoinerCommentStub extends Model { + protected $table = 'comments'; } class MorphOneStub extends Model {