diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2022-03-09 15:37:00 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-03-09 15:37:00 +0000 |
| commit | 03989d1dce80999bb9ea1a7d36df3285e5ce4c3b (patch) | |
| tree | d8077f5e32748a6ca658c51b8a7a02c47e0bf78f /lib | |
| parent | e790b11460ffaf8cc68b309ad47fe0e314b2c67f (diff) | |
| parent | 0a8edf6feb25a046505ef79796695fac90c152d4 (diff) | |
| download | sqlalchemy-03989d1dce80999bb9ea1a7d36df3285e5ce4c3b.tar.gz | |
Merge "support adapt_on_names for with_polymorphic" into main
Diffstat (limited to 'lib')
| -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, |
