]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
More replacements of mapper to map_imperatively
authorFederico Caselli <cfederico87@gmail.com>
Fri, 15 Jan 2021 19:30:46 +0000 (20:30 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Fri, 15 Jan 2021 19:31:25 +0000 (20:31 +0100)
Ref: #5829
Change-Id: I6778fde8d2af66011c7a98beeb6d1b690c748afc

doc/build/orm/cascades.rst
doc/build/orm/composites.rst
doc/build/orm/inheritance.rst
doc/build/orm/join_conditions.rst
doc/build/orm/loading_columns.rst
doc/build/orm/mapping_columns.rst
doc/build/orm/session_state_management.rst

index 217692c73cf7b63dd3f08e63b25f8611f6a4a339..02990706ab246d47d9d74a1a69705e9453e7c384 100644 (file)
@@ -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``
index f6eec6f2cd407387b44d9f2c8f6ee12a2c959af0..fb3ca476783f488d0e884928def0600bc0d8ecf3 100644 (file)
@@ -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),
     })
index 12f18c04ad68818ddbadff2e88f240f9fcd5e684..12f59365df087099a3efc0170c27527f2957e8b4 100644 (file)
@@ -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"
index 80965b5a33b18cccca945ef7bf8e4bfa79fa8d3c..52ae156b24d2776d50209658df99a00850992a29 100644 (file)
@@ -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,
index 9566d0efcfac5968400257c38dc4f2a0f425a33b..7b0530a7e8588e6b8dcfbbfe3d0cc1b0cbf0e93c 100644 (file)
@@ -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)
     })
 
index 948334c731016972cb60907fe66e233c00a2bf47..596c64f7c5aad43555ae69290c0e562fe3b6f0c7 100644 (file)
@@ -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,
     })
index 40e50cda15abcc8f963025b9bcdbae0c8c205cac..b91ffadb40b011251ca0e7b7a1a7e3210f28672c 100644 (file)
@@ -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