F
Filament3mo ago
morty

Possible bug with exists rule on select multiple form components?

Thought I'd check here first before creating an issue on GitHub. I have the following form:
Forms\Components\CheckboxList::make('id')
->label('Collections')
->searchable()
->relationship(
'collections',
'name',
fn (Builder $query): Builder => $query->ownedByCurrentUser()
)
->exists(
AccountCollection::class,
'id',
fn (Exists $rule): Exists => $rule->where(
'user_id',
Auth::user()->id
)
),
Forms\Components\CheckboxList::make('id')
->label('Collections')
->searchable()
->relationship(
'collections',
'name',
fn (Builder $query): Builder => $query->ownedByCurrentUser()
)
->exists(
AccountCollection::class,
'id',
fn (Exists $rule): Exists => $rule->where(
'user_id',
Auth::user()->id
)
),
It's just a simple checkbox list for a many-to-many relationship between an account and an account_collection. The relationship query is being modified to only show collections owned by the authenticated user. The exists query is being modified to only check what should be only selected collections. The problem occurs when another authenticated users tries to add the account to one of their collections if the account already belongs to a collection from another user. For example, in the second screenshot, you can see the user trying to add the account to a single one of their collections but for some reason the exists() validation rule is still checking against all collections the account belongs to which obviously fails because of the where constraint on the exists rule. The query looks like this:
SELECT
count(DISTINCT [id]) AS aggregate
FROM
[crm].[account_collections]
WHERE
[id] in('8', '20', '11', '13', '21', '1')
AND [user_id] = '9BB4A175-E83A-4E2F-9B52-3BA3F56CA0AE'
SELECT
count(DISTINCT [id]) AS aggregate
FROM
[crm].[account_collections]
WHERE
[id] in('8', '20', '11', '13', '21', '1')
AND [user_id] = '9BB4A175-E83A-4E2F-9B52-3BA3F56CA0AE'
When it should only look like this:
SELECT
count(DISTINCT [id]) AS aggregate
FROM
[crm].[account_collections]
WHERE
[id] in('1')
AND [user_id] = '9BB4A175-E83A-4E2F-9B52-3BA3F56CA0AE'
SELECT
count(DISTINCT [id]) AS aggregate
FROM
[crm].[account_collections]
WHERE
[id] in('1')
AND [user_id] = '9BB4A175-E83A-4E2F-9B52-3BA3F56CA0AE'
Is this a bug?
No description
No description
0 Replies
No replies yetBe the first to reply to this messageJoin