From da12764b15ac3f06f306918455a18b83fe12ee81 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Fri, 15 Jan 2021 20:30:46 +0100 Subject: [PATCH] More replacements of mapper to map_imperatively Ref: #5829 Change-Id: I6778fde8d2af66011c7a98beeb6d1b690c748afc --- doc/build/orm/cascades.rst | 7 ++--- doc/build/orm/composites.rst | 2 +- doc/build/orm/inheritance.rst | 32 ++++++++++++++-------- doc/build/orm/join_conditions.rst | 5 ++-- doc/build/orm/loading_columns.rst | 2 +- doc/build/orm/mapping_columns.rst | 2 +- doc/build/orm/session_state_management.rst | 4 +-- 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/doc/build/orm/cascades.rst b/doc/build/orm/cascades.rst index 217692c73c..02990706ab 100644 --- a/doc/build/orm/cascades.rst +++ b/doc/build/orm/cascades.rst @@ -569,7 +569,7 @@ default takes place on attribute change events emitted from backrefs. This is probably a confusing statement more easily described through demonstration; it means that, given a mapping such as this:: - mapper(Order, order_table, properties={ + mapper_registry.map_imperatively(Order, order_table, properties={ 'items' : relationship(Item, backref='order') }) @@ -592,9 +592,8 @@ place:: This behavior can be disabled using the :paramref:`_orm.relationship.cascade_backrefs` flag:: - mapper(Order, order_table, properties={ - 'items' : relationship(Item, backref='order', - cascade_backrefs=False) + mapper_registry.map_imperatively(Order, order_table, properties={ + 'items' : relationship(Item, backref='order', cascade_backrefs=False) }) So above, the assignment of ``i1.order = o1`` will append ``i1`` to the ``items`` diff --git a/doc/build/orm/composites.rst b/doc/build/orm/composites.rst index f6eec6f2cd..fb3ca47678 100644 --- a/doc/build/orm/composites.rst +++ b/doc/build/orm/composites.rst @@ -64,7 +64,7 @@ attributes that will represent sets of columns via the ``Point`` class:: A classical mapping above would define each :func:`.composite` against the existing table:: - mapper(Vertex, vertices_table, properties={ + mapper_registry.map_imperatively(Vertex, vertices_table, properties={ 'start':composite(Point, vertices_table.c.x1, vertices_table.c.y1), 'end':composite(Point, vertices_table.c.x2, vertices_table.c.y2), }) diff --git a/doc/build/orm/inheritance.rst b/doc/build/orm/inheritance.rst index 12f18c04ad..12f59365df 100644 --- a/doc/build/orm/inheritance.rst +++ b/doc/build/orm/inheritance.rst @@ -870,17 +870,27 @@ A constructor similar to that supplied by Declarative is illustrated:: class Engineer(Employee): pass - employee_mapper = mapper(Employee, pjoin, - with_polymorphic=('*', pjoin), - polymorphic_on=pjoin.c.type) - manager_mapper = mapper(Manager, managers_table, - inherits=employee_mapper, - concrete=True, - polymorphic_identity='manager') - engineer_mapper = mapper(Engineer, engineers_table, - inherits=employee_mapper, - concrete=True, - polymorphic_identity='engineer') + employee_mapper = mapper_registry.map_imperatively( + Employee, + pjoin, + with_polymorphic=('*', pjoin), + polymorphic_on=pjoin.c.type, + ) + manager_mapper = mapper_registry.map_imperatively( + Manager, + managers_table, + inherits=employee_mapper, + concrete=True, + polymorphic_identity='manager', + ) + engineer_mapper = mapper_registry.map_imperatively( + Engineer, + engineers_table, + inherits=employee_mapper, + concrete=True, + polymorphic_identity='engineer', + ) + The "abstract" example can also be mapped using "semi-classical" or "classical" diff --git a/doc/build/orm/join_conditions.rst b/doc/build/orm/join_conditions.rst index 80965b5a33..52ae156b24 100644 --- a/doc/build/orm/join_conditions.rst +++ b/doc/build/orm/join_conditions.rst @@ -585,9 +585,10 @@ A classical mapping situation here is similar, where ``node_to_node`` can be joi to ``node.c.id``:: from sqlalchemy import Integer, ForeignKey, String, Column, Table, MetaData - from sqlalchemy.orm import relationship, mapper + from sqlalchemy.orm import relationship, registry metadata = MetaData() + mapper_registry = registry() node_to_node = Table("node_to_node", metadata, Column("left_node_id", Integer, ForeignKey("node.id"), primary_key=True), @@ -601,7 +602,7 @@ to ``node.c.id``:: class Node(object): pass - mapper(Node, node, properties={ + mapper_registry.map_imperatively(Node, node, properties={ 'right_nodes':relationship(Node, secondary=node_to_node, primaryjoin=node.c.id==node_to_node.c.left_node_id, diff --git a/doc/build/orm/loading_columns.rst b/doc/build/orm/loading_columns.rst index 9566d0efcf..7b0530a7e8 100644 --- a/doc/build/orm/loading_columns.rst +++ b/doc/build/orm/loading_columns.rst @@ -38,7 +38,7 @@ attribute is first referenced on the individual object instance:: Classical mappings as always place the usage of :func:`_orm.deferred` in the ``properties`` dictionary against the table-bound :class:`_schema.Column`:: - mapper(Book, book_table, properties={ + mapper_registry.map_imperatively(Book, book_table, properties={ 'photo':deferred(book_table.c.photo) }) diff --git a/doc/build/orm/mapping_columns.rst b/doc/build/orm/mapping_columns.rst index 948334c731..596c64f7c5 100644 --- a/doc/build/orm/mapping_columns.rst +++ b/doc/build/orm/mapping_columns.rst @@ -46,7 +46,7 @@ The corresponding technique for an :term:`imperative` mapping is to place the desired key in the :paramref:`_orm.mapper.properties` dictionary with the desired key:: - registry.mapper(User, user_table, properties={ + mapper_registry.map_imperatively(User, user_table, properties={ 'id': user_table.c.user_id, 'name': user_table.c.user_name, }) diff --git a/doc/build/orm/session_state_management.rst b/doc/build/orm/session_state_management.rst index 40e50cda15..b91ffadb40 100644 --- a/doc/build/orm/session_state_management.rst +++ b/doc/build/orm/session_state_management.rst @@ -10,8 +10,8 @@ It's helpful to know the states which an instance can have within a session: * **Transient** - an instance that's not in a session, and is not saved to the database; i.e. it has no database identity. The only relationship such an - object has to the ORM is that its class has a ``mapper()`` associated with - it. + object has to the ORM is that its class has a :class:`_orm.Mapper` associated + with it. * **Pending** - when you :meth:`~.Session.add` a transient instance, it becomes pending. It still wasn't actually flushed to the -- 2.47.2