]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
implement polymorphic_abstract=True feature
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 13 Jan 2023 22:24:14 +0000 (17:24 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 14 Jan 2023 21:45:01 +0000 (16:45 -0500)
commite07130c597422d5f9a5d734e1411d8fef0c2deff
treee3367d1d9c454998c19ae32c6c013e1fb1ff1321
parent0c5faf37c2c8779be4e587528a56f19b455a3576
implement polymorphic_abstract=True feature

Added a new parameter to :class:`_orm.Mapper` called
:paramref:`_orm.Mapper.polymorphic_abstract`. The purpose of this directive
is so that the ORM will not consider the class to be instantiated or loaded
directly, only subclasses. The actual effect is that the
:class:`_orm.Mapper` will prevent direct instantiation of instances
of the class and will expect that the class does not have a distinct
polymorphic identity configured.

In practice, the class that is mapped with
:paramref:`_orm.Mapper.polymorphic_abstract` can be used as the target of a
:func:`_orm.relationship` as well as be used in queries; subclasses must of
course include polymorphic identities in their mappings.

The new parameter is automatically applied to classes that subclass
the :class:`.AbstractConcreteBase` class, as this class is not intended
to be instantiated.

Additionally, updated some areas of the single table inheritance
documentation to include mapped_column(nullable=False) for all
subclass-only columns; the mappings as given didn't work as the
columns were no longer nullable using Annotated Declarative Table
style.

Fixes: #9060
Change-Id: Ief0278e3945a33a6ff38ac14d39c38ce24910d7f
doc/build/changelog/unreleased_20/9060.rst [new file with mode: 0644]
doc/build/orm/declarative_config.rst
doc/build/orm/inheritance.rst
lib/sqlalchemy/ext/declarative/extensions.py
lib/sqlalchemy/orm/mapper.py
test/ext/declarative/test_inheritance.py
test/orm/declarative/test_inheritance.py
test/orm/inheritance/test_basic.py
test/orm/inheritance/test_single.py