Fundamentally the cascade applies to doing something to the 'many' side when something happens on the 'one' side.

A many-to-many association can't do this sort of things, and in fact, you can't just 'create' a many-to-many relationship in a relational database. To implement a many-to-many relationship, you need an intermediary table that is many-to-one with each of the two sides to build that many-to-many relationship.

You could use a cascade to update this interconnection table, to delete the cross connection terms when you delete one side of a relationship (and if you don't you can't delete the items without first removing all the relationships). By itself, this doesn't help you, but you could create a trigger on deleting this crossing element, and have it check if after it is gone if the secret it was connected to is now no longer referenced, and if so delete the secret.


On 11/2/21 4:49 PM, 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/b5e4faee-5cd6-4b9b-936b-0d80458f55e4n%40googlegroups.com <https://groups.google.com/d/msgid/sqlalchemy/b5e4faee-5cd6-4b9b-936b-0d80458f55e4n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Richard Damon

--
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/35a2e6f8-d375-2054-fd9a-758fdf2f227d%40Damon-Family.org.

Reply via email to