Filtering by a related table column changes the table id

Hi, I'm following the Owners, Pets, Treatments demo and I'm having issues creating a simple toggle filter by owner's email for the Patients resource.
Tables\Filters\Filter::make('owner_email')
    ->label('Owner email is John Doe')
    ->toggle()
    ->baseQuery(function (Builder $query): Builder {
        return $query
            ->join('owners', 'patients.owner_id', '=', 'owners.id');
    })
    ->query(function (Builder $query): Builder {
        return $query
            ->where('owners.email', '=', 'john@doe.com');
    }),

My problem is that after applying filter, the Patients table now uses the owner's id instead of the patients id. What I'm doing wrong?
Screenshot_2023-11-23_at_11.44.01.png
Screenshot_2023-11-23_at_11.44.06.png
Screenshot_2023-11-23_at_11.41.08.png
Screenshot_2023-11-23_at_11.42.17.png
Solution
You are adding a join with a table that also has an ID. Try adding a select('your_table.*') via the table query
Was this page helpful?