Come to think of it, mapping to *None* doesn’t make much sense because then there’s no mapper.
However, it probably would make sense to define an “invalid” mapped Point if all mapped columns are NULL. In that case, I’d still consider adding check constraints to mildly improve integrity, although if any one mapped properties is NULL then by definition to Point would be invalid. Hmm 🤔 On Wednesday, November 15, 2023 at 9:02:16 AM UTC+10 jens.t...@gmail.com wrote: > Hello everyone, > > I wanted to follow up on the examples on Composite Column Types > <https://docs.sqlalchemy.org/en/20/orm/composites.html> and in particular > setting the mapped composite value in Python-land to *None*. > > For instance, this class > @dataclasses.dataclass > class Point: > x: int > y: int > is used in the following composite mapping and I’d like the two mapped > properties to be optional (for the sake of the argument, whether it makes > sense or not): > class Vertex(Base): > start: Mapped[Point] | None = composite(mapped_column("x1"), > mapped_column("y1")) > end: Mapped[Point] | None = composite(mapped_column("x2"), > mapped_column("y2"))The optional would then have to map to *nullable=True* > for > both mapped columns, which in turn would need to be checked to ensure > integrity — either both or neither of the two mapped columns for a *Point* > can be NULL at the same time. > > I wasn’t able to find a recipe > <https://docs.sqlalchemy.org/en/20/orm/examples.html> for this use case. > What’s the recommendation to implement this? Will I have to roll most of > this manually, or does SQLA provide support? > > Much thanks! > Jens > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/e3f64225-bcad-4fde-b77a-08312a0cc46dn%40googlegroups.com.