diff --git a/src/SleepingOwl/WithJoin/WithJoinEloquentBuilder.php b/src/SleepingOwl/WithJoin/WithJoinEloquentBuilder.php index 15728ed..3b3047b 100644 --- a/src/SleepingOwl/WithJoin/WithJoinEloquentBuilder.php +++ b/src/SleepingOwl/WithJoin/WithJoinEloquentBuilder.php @@ -62,7 +62,7 @@ protected function isNestedRelation($relation) */ protected function addNestedRelations($name, Relation $relation) { - $nestedRelations = $this->nestedRelations($name); + $nestedRelations = $getOtherKey = method_exists($this, 'nestedRelations') ? $this->nestedRelations($name) : $this->relationsNestedUnder($name); if (count($nestedRelations) <= 0) return; $class = $relation->getRelated(); @@ -82,6 +82,7 @@ protected function addNestedRelations($name, Relation $relation) protected function addJoinToQuery($joinTableAlias, $currentTableAlias, Relation $relation, $columnsPrefix = '') { $joinTableName = $relation->getRelated()->getTable(); + $getOtherKey = !method_exists($relation, 'getOtherKey') ? $relation->getOwnerKey() : $relation->getOtherKey(); $joinTable = implode(' as ', [ $joinTableName, @@ -89,7 +90,7 @@ protected function addJoinToQuery($joinTableAlias, $currentTableAlias, Relation ]); $joinLeftCondition = implode('.', [ $joinTableAlias, - $relation->getOtherKey() + $getOtherKey ]); $joinRightCondition = implode('.', [ $currentTableAlias,