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')
})
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``
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),
})
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"
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),
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,
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)
})
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,
})
* **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