Rawrocopter
Rawrocopter
FFilament
Created by Rawrocopter on 9/10/2023 in #❓┊help
Select Filter with Custom FK
I am adding a select filter that I think should be pretty standard, but I will admit that I am pretty new to Filament. I have 2 related models: SlackUser, which has a PK of id, but a unique id of slack_id. I have a relationship from another model that uses this unique key, rather than the primary key.
public function slackUser()
{
return $this->belongsTo(SlackUser::class, 'sender', 'slack_id');
}
public function slackUser()
{
return $this->belongsTo(SlackUser::class, 'sender', 'slack_id');
}
And in Filament, I am trying to use this relatioship as a filter to be able to select based on Slack user. Filter code looks like this:
->filters([
SelectFilter::make('sender')
->relationship('slackUser', 'name')
])
->filters([
SelectFilter::make('sender')
->relationship('slackUser', 'name')
])
The names of the users display properly, but the filter doesn't seem to be working properly. The URL that is generated when applying the filter looks correct to me:
?tableFilters[sender][value]=ABC123
?tableFilters[sender][value]=ABC123
but if I log out the query, it doesn't seem to be using the custom owner key that is provided in the relationship:
SELECT
count(*) AS aggregate
FROM
"messages"
WHERE (EXISTS (
SELECT
*
FROM
"slack_users"
WHERE
"messages"."sender" = "slack_users"."slack_id"
AND "slack_users"."id" = 'ABC123'));
SELECT
count(*) AS aggregate
FROM
"messages"
WHERE (EXISTS (
SELECT
*
FROM
"slack_users"
WHERE
"messages"."sender" = "slack_users"."slack_id"
AND "slack_users"."id" = 'ABC123'));
Any ideas why it wouldn't be picking up the custom owner key in this situation? Thanks!
1 replies