diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-08 09:34:09 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-08 13:25:46 -0500 |
| commit | 0a8edf6feb25a046505ef79796695fac90c152d4 (patch) | |
| tree | e2fe6cbdce54995f21cb6ec631d5d783747ea355 /lib/sqlalchemy | |
| parent | a289e05226e20cc6de9deb479f63297320ef7c5c (diff) | |
| download | sqlalchemy-0a8edf6feb25a046505ef79796695fac90c152d4.tar.gz | |
support adapt_on_names for with_polymorphic
Added :paramref:`_orm.with_polymorphic.adapt_on_names` to the
:func:`_orm.with_polymorphic` function, which allows a polymorphic load
(typically with concrete mapping) to be stated against an alternative
selectable that will adapt to the original mapped selectable on column
names alone.
Fixes: #7805
Change-Id: I933e180a489fec8a6f4916d1622d444dd4434f30
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/_orm_constructors.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/util.py | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/_orm_constructors.py b/lib/sqlalchemy/orm/_orm_constructors.py index 8e05c6ef2..8d5fb91d0 100644 --- a/lib/sqlalchemy/orm/_orm_constructors.py +++ b/lib/sqlalchemy/orm/_orm_constructors.py @@ -2110,6 +2110,7 @@ def with_polymorphic( flat=False, polymorphic_on=None, aliased=False, + adapt_on_names=False, innerjoin=False, _use_mapper_path=False, ): @@ -2173,6 +2174,15 @@ def with_polymorphic( :param innerjoin: if True, an INNER JOIN will be used. This should only be specified if querying for one specific subtype only + + :param adapt_on_names: Passes through the + :paramref:`_orm.aliased.adapt_on_names` + parameter to the aliased object. This may be useful in situations where + the given selectable is not directly related to the existing mapped + selectable. + + .. versionadded:: 1.4.33 + """ return AliasedInsp._with_polymorphic_factory( base, @@ -2180,6 +2190,7 @@ def with_polymorphic( selectable=selectable, flat=flat, polymorphic_on=polymorphic_on, + adapt_on_names=adapt_on_names, aliased=aliased, innerjoin=innerjoin, _use_mapper_path=_use_mapper_path, diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index e00e05954..d4faf10e3 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -757,7 +757,9 @@ class AliasedInsp( # are not even the thing we are mapping, such as embedded # selectables in subqueries or CTEs. See issue #6060 adapt_from_selectables=[ - m.selectable for m in self.with_polymorphic_mappers + m.selectable + for m in self.with_polymorphic_mappers + if not adapt_on_names ], ) @@ -810,6 +812,7 @@ class AliasedInsp( polymorphic_on=None, aliased=False, innerjoin=False, + adapt_on_names=False, _use_mapper_path=False, ): @@ -830,6 +833,7 @@ class AliasedInsp( base, selectable, with_polymorphic_mappers=mappers, + adapt_on_names=adapt_on_names, with_polymorphic_discriminator=polymorphic_on, use_mapper_path=_use_mapper_path, represents_outer_join=not innerjoin, |
