]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add caveat for bulk deletes that they are generally not feasible
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 12 Sep 2016 22:17:18 +0000 (18:17 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 12 Sep 2016 22:17:53 +0000 (18:17 -0400)
for joined inheritance

Change-Id: I043a5842401d586aa3ff96d05e06b443ff03fa60
(cherry picked from commit 2cd53196ea2df7b9006dcc48fb79555eb533f5cc)

lib/sqlalchemy/orm/query.py

index b5151c109642da14d3176beaf6c876eb57fe7d16..bbb6cd5193dde401eea1457fcf300eaab434411f 100644 (file)
@@ -3024,6 +3024,32 @@ class Query(object):
 
         .. warning:: **Additional Caveats for bulk query deletes**
 
+            * This method does **not work for joined
+              inheritance mappings**, since the **multiple table
+              deletes are not supported by SQL** as well as that the
+              **join condition of an inheritance mapper is not
+              automatically rendered**.  Care must be taken in any
+              multiple-table delete to first accomodate via some other means
+              how the related table will be deleted, as well as to
+              explicitly include the joining
+              condition between those tables, even in mappings where
+              this is normally automatic. E.g. if a class ``Engineer``
+              subclasses ``Employee``, a DELETE against the ``Employee``
+              table would look like::
+
+                    session.query(Engineer).\\
+                        filter(Engineer.id == Employee.id).\\
+                        filter(Employee.name == 'dilbert').\\
+                        delete()
+
+              However the above SQL will not delete from the Engineer table,
+              unless an ON DELETE CASCADE rule is established in the database
+              to handle it.
+
+              Short story, **do not use this method for joined inheritance
+              mappings unless you have taken the additional steps to make
+              this feasible**.
+
             * The method does **not** offer in-Python cascading of
               relationships - it is assumed that ON DELETE CASCADE/SET
               NULL/etc. is configured for any foreign key references