You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The last $parent->getMorphClass() should be $relation->getMorphClass(), in particular when the relation is a morphedByMany. So this elseif statement needs to be split.
I dont have a good testcase but here's the main setup that causes the bug:
// App\Models\Asset.php (Eloquent model)
protected $searchableColumns = ['users.username'];
public function users()
{
return $this->morphedByMany(User::class, 'morphable', 'asset_relations');
}
// App\Models\User.php (Eloquent model)
public function assets()
{
return $this->morphToMany(Asset::class, 'morphable', 'asset_relations');
}
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 on morphable_type = App\Models\Asset instead of the correct App\Models\User.
The text was updated successfully, but these errors were encountered:
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
eloquence-base/src/Relations/Joiner.php
Line 147 in 46f885c
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
.The text was updated successfully, but these errors were encountered: