Open bert-w opened 5 years ago
any chance for a PR with fix?
I would PR it but I wasnt sure if this was the correct solution.
I added another fix to the pull request, because when searching in more than one morphable relation I got SQL errors "'morphable_type' in on clause is ambiguous".
It appears that I cant search properly in my
morphedByMany
relations.I've tracked it down to https://github.com/jarektkaczyk/eloquence-base/blob/46f885cde97704bb263faa237fba6760b838bb5a/src/Relations/Joiner.php#L147
The last
$parent->getMorphClass()
should be$relation->getMorphClass()
, in particular when the relation is amorphedByMany
. So this elseif statement needs to be split.I dont have a good testcase but here's the main setup that causes the bug:
Lastly, try to make a query like this:
Asset::with(['user'])->search('somename')->get();
The SQL itself will generate the wrong query since
asset_relations
will be joined onmorphable_type = App\Models\Asset
instead of the correctApp\Models\User
.