Skip to content

Commit 9154455

Browse files
authored
Merge pull request #76 from jonneroelofs/master
added check to see if the used alias should be custom or user provided
2 parents 042a17a + a2e3cc2 commit 9154455

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/PowerJoins.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ trait PowerJoins
4040
public function scopeJoinRelationship(Builder $query, $relationName, $callback = null, $joinType = 'join', $useAlias = false, bool $disableExtraConditions = false): void
4141
{
4242
$joinType = PowerJoins::$joinMethodsMap[$joinType] ?? $joinType;
43+
$useAlias = is_string($callback) ? false : $useAlias;
4344
$callback = $this->formatJoinCallback($relationName, $callback);
4445

4546
if (is_null($query->getSelect())) {

tests/JoinRelationshipUsingAliasTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ public function test_joining_using_auto_generated_alias()
2424
$this->assertCount(1, $posts);
2525
}
2626

27+
/**
28+
* @test
29+
*/
30+
public function test_joining_using_provided_alias()
31+
{
32+
$category = factory(Category::class)->state('with:parent')->create();
33+
$post = factory(Post::class)->create(['category_id' => $category->id]);
34+
35+
$sql = Post::joinRelationshipUsingAlias('category', 'my_alias')->toSql();
36+
37+
$this->assertStringContainsString('my_alias', $sql);
38+
}
39+
2740
/**
2841
* @test
2942
*/

0 commit comments

Comments
 (0)