Skip to content

Commit 56bbdea

Browse files
committed
Added missing left and right join relationship methods for table alias
1 parent 614d053 commit 56bbdea

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/Mixins/JoinRelationship.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ public function joinRelationshipUsingAlias()
7777
};
7878
}
7979

80+
/**
81+
* Left join the relationship(s) using table aliases.
82+
*/
83+
public function leftJoinRelationshipUsingAlias()
84+
{
85+
return function ($relationName, $callback = null) {
86+
return $this->joinRelationship($relationName, $callback, 'leftJoin', true);
87+
};
88+
}
89+
90+
/**
91+
* Right join the relationship(s) using table aliases.
92+
*/
93+
public function rightJoinRelationshipUsingAlias()
94+
{
95+
return function ($relationName, $callback = null) {
96+
return $this->joinRelationship($relationName, $callback, 'rightJoin', true);
97+
};
98+
}
99+
80100
public function joinRelation()
81101
{
82102
return function ($relationName, $callback = null, $joinType = 'join') {
@@ -368,8 +388,8 @@ public function clearPowerJoinCaches()
368388
};
369389
}
370390

371-
public static function getAliasFor($relationName = null)
391+
public static function getAliasFor($model = null, $default = null)
372392
{
373-
return JoinRelationship::$powerJoinAliasesCache[$relationName] ?? null;
393+
return JoinRelationship::$powerJoinAliasesCache[spl_object_id($model)] ?? $default;
374394
}
375395
}

src/Mixins/RelationshipsExtraMethods.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public function getFarParent()
271271
public function getTableOrAliasForModel()
272272
{
273273
return function ($model, $default = null) {
274-
return JoinRelationship::$powerJoinAliasesCache[spl_object_id($model)] ?? $default;
274+
return JoinRelationship::getAliasFor($model, $default);
275275
};
276276
}
277277
}

0 commit comments

Comments
 (0)