pg icon indicating copy to clipboard operation
pg copied to clipboard

Recursive delete?

Open hazcod opened this issue 4 years ago • 5 comments

Hi, any idea how to do a recursive delete? e..g for

CREATE TABLE domains (
    dom_id      serial  PRIMARY KEY,
    dom_domain  int     REFERENCES domains(dom_id),
);

hazcod avatar Apr 17 '20 07:04 hazcod

The way I would approach this would be adding a hook on AfterDelete

Janther avatar Apr 18 '20 00:04 Janther

The way I would approach this would be adding a hook on AfterDelete

Thats a very good idea! You mean BeforeDelete?

hazcod avatar Apr 18 '20 08:04 hazcod

A good question would be what do you do if one deletion fails. Perhaps the BeforeDelete might be more appropriate

Janther avatar Apr 18 '20 08:04 Janther

It should all be in a TX, so I wonder how hooks work with that.

hazcod avatar Apr 18 '20 08:04 hazcod

just execute the function that deletes the object with RunInTransaction

Janther avatar Apr 18 '20 09:04 Janther