File tree Expand file tree Collapse file tree
adminforth/documentation/docs/tutorial/08-Plugins Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments