Skip to content

Commit 604c0b3

Browse files
committed
docs: add documentation for cascade deletion
1 parent b4d8aa1 commit 604c0b3

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

adminforth/documentation/docs/tutorial/08-Plugins/03-ForeignInlineList.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,36 @@ plugins: [
187187

188188
```
189189

190-
This setup will show, in the show view for each record, the `aparts` resource without any filters. And you don’t have to modify the `aparts` resource.
190+
This setup will show, in the show view for each record, the `aparts` resource without any filters. And you don’t have to modify the `aparts` resource.
191+
192+
193+
## Cascade delete for foreign resources
194+
195+
There might be cases when you want to control what happens with child records when a parent record is deleted.
196+
You can configure this behavior in the `foreignResource` section using the `onDelete` option.
197+
198+
```ts title="./resources/apartments.ts"
199+
200+
export default {
201+
resourceId: 'aparts',
202+
...
203+
columns: [
204+
...
205+
{
206+
name: 'realtor_id',
207+
foreignResource: {
208+
resourceId: 'adminuser',
209+
//diff-add
210+
onDelete: 'cascade' // cascade or setNull
211+
//diff-add
212+
}
213+
}
214+
],
215+
}
216+
217+
```
218+
219+
#### The onDelete option supports two modes:
220+
221+
- `cascade`: When a parent record is deleted, all related child records will be deleted automatically.
222+
- `setNull`: When a parent record is deleted, child records will remain, but their foreign key will be set to null.

0 commit comments

Comments
 (0)