allowDuplicateRelations detach not working as expected
- Laravel Version: 11.44.2
- Nova Version: 5.5.4
- PHP Version: 8.3.20
- Database Driver & Version: PG
- Reproduction Repository: https://github.com/potsky/nova
Description:
Same as #6496. Deleting a relation deletes all relations.
https://cln.sh/C6wChd7rBFGpMy6rVSkZ
Detailed steps to reproduce the issue on a fresh Nova installation:
- https://github.com/potsky/nova
-
composer install -
php artisan migrate --seed - Go to https://nova.test/nova/resources/contract-resources/1 with
[email protected]/password - Delete a resource, it deletes all related resources.
Unable to access https://github.com/potsky/nova
Done public now
Any update on this?
Any update on this @crynobone ?
At the moment, the code is working as expected.
BelongsToMany::make('Items', 'items', ItemResource::class)
->fields(new ContractItemFields())
->allowDuplicateRelations()
->withSubtitles()
->searchable()
->referToPivotAs('Scope'),
The 3rd parameter refers to ItemResource and doesn't have knowledge about ContactResource. As conclusion, it would be using definition from Item model to resolve everything instead of Contact model.
At the moment, the code is working as expected.
BelongsToMany::make('Items', 'items', ItemResource::class) ->fields(new ContractItemFields()) ->allowDuplicateRelations() ->withSubtitles() ->searchable() ->referToPivotAs('Scope'), The 3rd parameter refers to
ItemResourceand doesn't have knowledge aboutContactResource. As conclusion, it would be using definition fromItemmodel to resolve everything instead ofContactmodel.
Yes so it should take into account the id in ->withPivot('id', 'role') and not deleting all resources...
You have written this here : https://github.com/laravel/nova-issues/issues/6496#issuecomment-2275281262
The problem is on your Item model it doesn't have those definition:
Ok, I have added the same in Item, same behaviour.
Any ETA @crynobone please ?