[sqlalchemy] Re: ORM-level “delete” cascade vs. FOREIGN KEY level “ON DELETE” cascade explanation
Hello, first of all, thnak you for your fast answer. I was refering to : > > A database level ON DELETE cascade is configured effectively on the > *many-to-one* side of the relationship; that is, we configure it relative > to the FOREIGN KEY constraint that is the “many” side of a relationship. > At the ORM level, *this direction is reversed*. SQLAlchemy handles the > deletion of “child” objects relative to a “parent” from the “parent” side, > which means that delete and delete-orphan cascade are configured on the > *one-to-many* side Marc V. -- 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/8a5b9f82-e20a-4bb7-a7cc-eeb6c87d6719%40googlegroups.com.
[sqlalchemy] ORM-level “delete” cascade vs. FOREIGN KEY level “ON DELETE” cascade explanation
Hello, I'm currently auditing a database which uses sqlalchemy 1.1.9 and PostgreSQL 10 with Python 3.5. There are a few foreign keys which are set to *ON DELETE CASCADE* on the database but are not set as such on the ORM side. My first thought was to simply add in the ForeignKey, a *ondelete='CASCADE'* but then I saw this article: https://docs.sqlalchemy.org/en/13/orm/cascades.html - ORM-level “delete” cascade vs. FOREIGN KEY level “ON DELETE” cascade. What I don't understand is, why would I want the ORM to handle the cascade if it explicitly says : > Database level ON DELETE cascade is *vastly more efficient* than that of > SQLAlchemy. Furthermore how sqlachemy cascade handles collisions with the database cascade if the first one uses a one-to-many schema while the other one uses a many-to-one ? And finally, should I follow my first idea and simply add the *ondelete='CASCADE'* and expect the same behavior as before ? Best regards, Marc V. -- 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/02b34afa-4f4e-46bb-9c46-6012e19d25f8%40googlegroups.com.