Filament ignoring foreign key constraints

Pretty simple, i have a foreign key constraint on a table, but filament is able to delete records i'm not allowed to delete in the database? Is there some sort of option I need to enable?
Solution:
i found out why it didn't work, i was using soft deletes 🙂
Jump to solution
6 Replies
ChesterS
ChesterS9mo ago
Sorry, what do you mean
filament is able to delete records i'm not allowed to delete
I don't think it's possible for filament to know what constraints you have in the database. You will have to either check manually or add some sort of validation.
DanielvdSpoel
DanielvdSpoel9mo ago
I mean.. somehow filament disables the constraints? i was expecting a 500 error, but i was allowed to delete it which is super weird imo
ChesterS
ChesterS9mo ago
If you have a constraint in the database (I assume a foreign key or something similar), filament should not be able to remove it, unless they do some REALLY funky stuff behind the scenes - which I doubt. Are you sure there's not something else going on? Can you give add some examples? Like the migration definition and the code that should fail?
DanielvdSpoel
DanielvdSpoel8mo ago
code is just a basic delete action on the store resource and then i have these constraints:
$table->foreign('store_id')->references('id')->on('stores')->onDelete('restrict');
$table->foreign('organization_id')->references('id')->on('organizations')->onDelete('restrict');
$table->foreign('store_id')->references('id')->on('stores')->onDelete('restrict');
$table->foreign('organization_id')->references('id')->on('organizations')->onDelete('restrict');
i would love to know why these don't work for filament
awcodes
awcodes8mo ago
Shouldn’t you have ->constrained() on there too? Or use ->restrictOnDelete()
Solution
DanielvdSpoel
DanielvdSpoel8mo ago
i found out why it didn't work, i was using soft deletes 🙂