diff --git a/src/Relations/Joiner.php b/src/Relations/Joiner.php index 1197b16..3dc0315 100644 --- a/src/Relations/Joiner.php +++ b/src/Relations/Joiner.php @@ -145,8 +145,8 @@ protected function getJoinClause(Model $parent, Relation $relation, $table, $typ if ($relation instanceof MorphOneOrMany) { $join->where($relation->getQualifiedMorphType(), '=', $parent->getMorphClass()); - } elseif ($relation instanceof MorphToMany || $relation instanceof MorphMany) { - $join->where($relation->getMorphType(), '=', $parent->getMorphClass()); + } elseif ($relation instanceof MorphToMany) { + $join->where($relation->getTable() . '.' . $relation->getMorphType(), '=', $relation->getMorphClass()); } return $join; diff --git a/tests/JoinerTest.php b/tests/JoinerTest.php index 5c285fb..70bc292 100644 --- a/tests/JoinerTest.php +++ b/tests/JoinerTest.php @@ -40,7 +40,7 @@ public function it_joins_morph_to_many_relations() $sql = 'select * from "users" ' . 'inner join "profiles" on "users"."profile_id" = "profiles"."id" ' . 'inner join "taggables" on "taggables"."taggable_id" = "profiles"."id" ' . - 'inner join "tags" on "taggables"."joiner_tag_stub_id" = "tags"."id" and "taggable_type" = ?'; + 'inner join "tags" on "taggables"."joiner_tag_stub_id" = "tags"."id" and "taggables"."taggable_type" = ?'; $query = $this->getQuery(); $joiner = $this->factory->make($query);