Interesting problem... it's not exactly a cascade delete, which goes from parent (1 side) to children (many side).
I think you have to provide code to do this - brute force check the parent to see if it's an "empty nester". This can be expensive if you are cascading a person delete to many person-secrets. You might consider maintaining a count in secret to prune the query. LogicBank <https://github.com/valhuber/LogicBank> (part of ApiLogicServer <https://github.com/valhuber/ApiLogicServer/blob/main/README.md> - both are open source) can maintain such counts without code, happy to discuss with you if you want to reach out. Regards, Val On Tuesday, November 2, 2021 at 1:49:17 PM UTC-7 Anders Buch wrote: > Hello All, > > Suppose I have a table of people, a table of secrets, and a many-to-many > association table between them. A person can exist without knowing any > secrets, but a secret without any associated people might as well be > deleted. My reading of the documentation is that it is not possible to set > cascade options to obtain this behavior? (Because a cascade delete option > would cause a secret to be deleted if any person forgets about it?) If > correct, is there another elegant way to achieve this? > > Thanks in advance! > Anders Buch > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/fde3d025-fda7-420b-b476-7dd295837f79n%40googlegroups.com.