Relationship manager with `distinct()` in query displaying duplicate rows
I have a database pivot table between two models (Client, Carrier). The pivot table contains another nullable foreign key to a Route model.
This relation manager is on my
ClientResource
, and should display unique Carrier
records based on this pivot table.
My relationship is defined as:
When called outside of filament this relationship is working and 2 rows are returned (desired outcome). When filament uses this relationship in the relation manager it adds more to the select in the form of pivot ids and the query returns 3 rows (the distinct() no longer applies?).
Thanks!Solution:Jump to solution
I've added the following to my table and it seems to be returning better results.
```php
->modifyQueryUsing(function (Builder $query) {
$query->select(DB::raw('distinct carriers.id, carriers.*'));...
2 Replies
The query run outside of filament looks like:
If I dump the query the relation manager table is running it looks like:
So it is adding to the select, and the distinct is being affected.
Solution
I've added the following to my table and it seems to be returning better results.