]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
group together with_polymorphic for single inh criteria
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Mar 2025 16:31:10 +0000 (11:31 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 5 Mar 2025 20:13:14 +0000 (15:13 -0500)
commit7fb3ef3e2db5c36ed554fc2e16c39c6cd17e34d2
treeb1a24a9f1b05ac3ec24a0c879a5644a51b2d66a4
parentd9b4d8ff3aae504402d324f3ebf0b8faff78f5dc
group together with_polymorphic for single inh criteria

The behavior of :func:`_orm.with_polymorphic` when used with a single
inheritance mapping has been changed such that its behavior should match as
closely as possible to that of an equivalent joined inheritance mapping.
Specifically this means that the base class specified in the
:func:`_orm.with_polymorphic` construct will be the basemost class that is
loaded, as well as all descendant classes of that basemost class.
The change includes that the descendant classes named will no longer be
exclusively indicated in "WHERE polymorphic_col IN" criteria; instead, the
whole hierarchy starting with the given basemost class will be loaded.  If
the query indicates that rows should only be instances of a specific
subclass within the polymorphic hierarchy, an error is raised if an
incompatible superclass is loaded in the result since it cannot be made to
match the requested class; this behavior is the same as what joined
inheritance has done for many years. The change also allows a single result
set to include column-level results from multiple sibling classes at once
which was not previously possible with single table inheritance.

Fixes: #12395
Change-Id: I9307b236a6de8c47e452fb8f982098c54edb811a
doc/build/changelog/unreleased_21/12395.rst [new file with mode: 0644]
lib/sqlalchemy/orm/context.py
lib/sqlalchemy/orm/mapper.py
test/orm/inheritance/test_single.py