Skip to content

Commit

Permalink
Merge pull request #97 from jonneroelofs/jr_fix_wheres_become_collection
Browse files Browse the repository at this point in the history
Fixed using withTrashed and having an alias on a join clause
  • Loading branch information
luisdalmolin authored Apr 6, 2022
2 parents f66789d + 3eef220 commit 98e0ecc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PowerJoinClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function useTableAliasInConditions()
}

return $where;
});
})->toArray();

return $this;
}
Expand Down
27 changes: 27 additions & 0 deletions tests/SoftDeletesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,31 @@ public function it_can_include_only_trashed()
$query
);
}

/** @test */
public function it_can_disable_soft_deletes_when_using_an_alias()
{
// making sure the query doesn't fail
UserProfile::query()
->joinRelationship('user', function ($join) {
$join->withTrashed();
})->get();

$query = UserProfile::query()
->joinRelationship('user', function ($join) {
$join->as('myAlias');
$join->withTrashed();
})
->toSql();

$this->assertStringContainsString(
'inner join "users" as "myAlias" on "user_profiles"."user_id" = "myAlias"."id"',
$query
);

$this->assertStringNotContainsString(
'"users"."deleted_at" is null',
$query
);
}
}

0 comments on commit 98e0ecc

Please sign in to comment.