jarektkaczyk / eloquence-base

base for the Eloquence extensions + Searchable
https://softonsofa.com
MIT License
77 stars 69 forks source link

Many-to-many polymorphic relation not joining correctly #5

Closed ncolgrove closed 5 years ago

ncolgrove commented 5 years ago

The joiner won't complete many-to-many polymorphic relation joins on both the join id and the join type. Models with relationships like those in Eloquent documentation:

public function tags()
{
   return $this->morphToMany('App\Tag', 'taggable');
}

result in partial joins like:

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"'

Join SQL is missing second type option:

... and "taggable_type" = ?

This would be similar to the morphOne option that exists today:

select * from "users" 
  inner join "profiles" on "users"."profile_id" = "profiles"."id" 
  inner join "companies" on "companies"."morphable_id" = "profiles"."id" and "companies"."morphable_type" = ?
jarektkaczyk commented 5 years ago

merged, thanks