How to trigger dal actions after record deletion

43 views
Skip to first unread message

Alan Etkin

unread,
Feb 3, 2026, 6:32:25 AM (8 days ago) Feb 3
to py4web
Hi!

I'm searching on the docs but can't find how to solve this:

Consider this model example

db.define_table(
"mytable",
Field("other_table_name"),
Field("other_table_record_id")
)

It's sort of a way of refering to any table in the db and point to a given record

What I'm looking for is a way of triggering a routine for removing broken references (to deleted records). AFAIK, there is no table ondelete lambda to achieve this. Maybe I could customize the delete form processing, but perhaps there is another way I'm missing so this action can be triggered for any delete action on the table.

Thanks

Alan

Christian Varas

unread,
Feb 3, 2026, 6:52:10 AM (8 days ago) Feb 3
to Alan Etkin, py4web
Hello,
you can use the option ondelete cascade to delete automatically related records. 
Field(fieldname, type='string', length=None, default=DEFAULT,
      required=False, requires=DEFAULT,
      ondelete='CASCADE'
)

greetings.

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/6cc1b1b7-fb41-4c78-bd5b-5ddb997863ecn%40googlegroups.com.

Alan Etkin

unread,
Feb 3, 2026, 9:44:36 AM (8 days ago) Feb 3
to py4web
I'm aware of that feature, the problem is that my table has no foreing key constraints (it has no reference field types). To clarify a bit my previous post:

What I want is that every time a record from other_table that is referenced in "mytable" (by the custom fields "other_table_name" and "other_table_record_id") is deleted, also delete the "mytable" record that refers to it.

Thanks and regards

icodk

unread,
Feb 3, 2026, 12:33:41 PM (8 days ago) Feb 3
to py4web
What about :
db.mytable._before_insert db.mytable._after_insert db.mytable._before_update db.mytable._after_update db.mytable._before_delete db.mytable._after_deletefrom the doc

Alan Etkin

unread,
Feb 4, 2026, 6:32:28 AM (7 days ago) Feb 4
to py4web
Excelent! I missed that feature

Thank you very much folks

Alan

Massimo DiPierro

unread,
Feb 7, 2026, 8:11:11 PM (4 days ago) Feb 7
to py4web
One caveat. In web2py it does not matter, but in py4web these should be set in models and they will be global, as they are not thread safe to change in the actions.
Reply all
Reply to author
Forward
0 new messages