Skip to content

Commit

Permalink
Merge pull request jarektkaczyk#2 from maqduni/feature/take_in_accoun…
Browse files Browse the repository at this point in the history
…t_soft_delete

Add a unit test for testing nested relationships with soft deleted records.
  • Loading branch information
jarektkaczyk authored Mar 10, 2018
2 parents 93598ce + 3f2165e commit e7ff0e0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/JoinerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e7ff0e0

Please sign in to comment.