from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
- from sqlalchemy.orm import mapper
+ from sqlalchemy.orm import registry
from sqlalchemy.orm import relationship
+ mapper_registry = registry()
+
@dataclass
class User:
id: int = field(init=False)
Column('email_address', String(50)),
)
- mapper(User, user, properties={
+ mapper_registry.map_imperatively(User, user, properties={
'addresses': relationship(Address, backref='user', order_by=address.c.id),
})
- mapper(Address, address)
+ mapper_registry.map_imperatively(Address, address)
.. _orm_mapper_configuration_overview:
:func:`_orm.mapper` function looks for:
The class to be mapped
------------------------
+----------------------
This is a class that we construct in our application.
There are generally no restrictions on the structure of this class. [1]_
.. _orm_mapping_properties:
The properties dictionary
---------------------------
+-------------------------
This is a dictionary of all of the attributes
that will be associated with the mapped class. By default, the
:paramref:`_orm.mapper.properties` parameter.
Other mapper configuration parameters
----------------------------------------
+-------------------------------------
These flags are documented at :func:`_orm.mapper`.