filament/filament
3.2.83
11.9.1
3.5.0
8.3.7
Using the CheckboxList with an intermediate table and a different set of options gives wrong results, because it's not possible to set constraints for the relationship. Also the modifyQueryUsing
-method is scoped to the query for the target relationship and not the intermediate table. It seems like it is impossible to set contraints for the intermediate table relationship on the CheckboxList.
The docs also mention a related method modifyOptionsQueryUsing
but it doesn't exist:
https://filamentphp.com/docs/3.x/forms/fields/checkbox-list#customizing-the-relationship-query
From the repro repo app/Filament/Resources/TemplateResource/RelationManagers/GroupsRelationManager.php
:
private function getPermissionsForm()
{
$checkboxLists = [];
foreach ($this->template->allowedTargets as $target) {
$checkboxLists[] = CheckboxList::make('templatePermissions')
->label($target->name)
->relationship(
name: 'templatePermissions',
titleAttribute: 'name',
modifyQueryUsing: fn (Builder $query) => $query->where('template_id', $this->template->id),
)
->options(function () use ($target) {
$permissions = [];
$templatePermissions = Permission::where('destination_id', $target->id)->whereIn('name', ['download', 'upload'])->get();
foreach ($templatePermissions as $permission) {
$permissions[$permission->id] = $permission->name;
}
return $permissions;
})
->pivotData([
'template_id' => $this->template->id,
]);
}
return $checkboxLists;
}
This form is for a Group
-Model that is attached to a Template
-Model as an example in the repro repo. The Group
-model has a relationship templatePermissions
that should be scoped to the current Template
-record.
The modifyQueryUsing
seems to be ignored completely, because the entries in the intermediate table template_group_permission
are always overwritten if the same Group is attached to another Template.
So the problem is that it is impossible to tell Filament that the relationship has some constraints (here the template_id).
A Group
can be attached to a Template
and have a constrained relationship to that Template
-model through templatePermissions
using the intermediate table template_group_permission
. Even if the same Group
is attached to another Template
with the same permissions there should be new entries in the intermediate table instead of overwritten ones.
[email protected]
with password password
https://github.com/nilskretschmer/filament-intermediate-query-issue
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too