diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-30 18:13:36 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-30 19:45:04 -0400 |
commit | 575b6dded9a25fca693f0aa7f6d7c6e735490460 (patch) | |
tree | 4bc0c76ee49bdac200abe0ec73ade88564b727c0 /lib/sqlalchemy/sql/dml.py | |
parent | 406034d41a764f6fe24374d40c95e79d295f6e80 (diff) | |
download | sqlalchemy-575b6dded9a25fca693f0aa7f6d7c6e735490460.tar.gz |
Support extra / single inh criteria with ORM update/delete
The ORM bulk update and delete operations, historically available via the
:meth:`_orm.Query.update` and :meth:`_orm.Query.delete` methods as well as
via the :class:`_dml.Update` and :class:`_dml.Delete` constructs for
:term:`2.0 style` execution, will now automatically accommodate for the
additional WHERE criteria needed for a single-table inheritance
discrminiator. Joined-table inheritance is still not directly
supported. The new :func:`_orm.with_loader_criteria` construct is also
supported for all mappings with bulk update/delete.
Fixes: #5018
Fixes: #3903
Change-Id: Id90827cc7e2bc713d1255127f908c8e133de9295
Diffstat (limited to 'lib/sqlalchemy/sql/dml.py')
-rw-r--r-- | lib/sqlalchemy/sql/dml.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py index a9bccaeff..b7151ac7b 100644 --- a/lib/sqlalchemy/sql/dml.py +++ b/lib/sqlalchemy/sql/dml.py @@ -12,6 +12,7 @@ Provide :class:`_expression.Insert`, :class:`_expression.Update` and from sqlalchemy.types import NullType from . import coercions from . import roles +from .base import _entity_namespace_key from .base import _from_objects from .base import _generative from .base import ColumnCollection @@ -983,10 +984,30 @@ class DMLWhereBase(object): ) def filter(self, *criteria): - """A synonym for the :meth:`_dml.DMLWhereBase.where` method.""" + """A synonym for the :meth:`_dml.DMLWhereBase.where` method. + + .. versionadded:: 1.4 + + """ return self.where(*criteria) + def _filter_by_zero(self): + return self.table + + def filter_by(self, **kwargs): + r"""apply the given filtering criterion as a WHERE clause + to this select. + + """ + from_entity = self._filter_by_zero() + + clauses = [ + _entity_namespace_key(from_entity, key) == value + for key, value in kwargs.items() + ] + return self.filter(*clauses) + @property def whereclause(self): """Return the completed WHERE clause for this :class:`.DMLWhereBase` |