def __repr__(self):
return f"Vertex(start={self.start}, end={self.end})"
+.. tip:: In the example above the columns that represent the composites
+ (``x1``, ``y1``, etc.) are also accessible on the class but are not
+ correctly understood by type checkers.
+ If accessing the single columns is important they can be explicitly declared,
+ as shown in :ref:`composite_with_typing`.
+
The above mapping would correspond to a CREATE TABLE statement as:
.. sourcecode:: pycon+sql
or the string name of an existing mapped column. The following examples
illustrate an equivalent mapping as that of the main section above.
-* Map columns directly, then pass to composite
+Map columns directly, then pass to composite
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Here we pass the existing :func:`_orm.mapped_column` instances to the
- :func:`_orm.composite` construct, as in the non-annotated example below
- where we also pass the ``Point`` class as the first argument to
- :func:`_orm.composite`::
+Here we pass the existing :func:`_orm.mapped_column` instances to the
+:func:`_orm.composite` construct, as in the non-annotated example below
+where we also pass the ``Point`` class as the first argument to
+:func:`_orm.composite`::
from sqlalchemy import Integer
from sqlalchemy.orm import mapped_column, composite
start = composite(Point, x1, y1)
end = composite(Point, x2, y2)
-* Map columns directly, pass attribute names to composite
+.. _composite_with_typing:
+
+Map columns directly, pass attribute names to composite
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- We can write the same example above using more annotated forms where we have
- the option to pass attribute names to :func:`_orm.composite` instead of
- full column constructs::
+We can write the same example above using more annotated forms where we have
+the option to pass attribute names to :func:`_orm.composite` instead of
+full column constructs::
from sqlalchemy.orm import mapped_column, composite, Mapped
start: Mapped[Point] = composite("x1", "y1")
end: Mapped[Point] = composite("x2", "y2")
-* Imperative mapping and imperative table
+Imperative mapping and imperative table
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- When using :ref:`imperative table <orm_imperative_table_configuration>` or
- fully :ref:`imperative <orm_imperative_mapping>` mappings, we have access
- to :class:`_schema.Column` objects directly. These may be passed to
- :func:`_orm.composite` as well, as in the imperative example below::
+When using :ref:`imperative table <orm_imperative_table_configuration>` or
+fully :ref:`imperative <orm_imperative_mapping>` mappings, we have access
+to :class:`_schema.Column` objects directly. These may be passed to
+:func:`_orm.composite` as well, as in the imperative example below::
mapper_registry.map_imperatively(
Vertex,