[Sqlalchemy-tickets] Issue #4168: Nested composite column types (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Psyche N. <iss...@bi...> - 2018-01-22 12:09:47
|
New issue 4168: Nested composite column types https://bitbucket.org/zzzeek/sqlalchemy/issues/4168/nested-composite-column-types Psyche NA: According to the [document](http://docs.sqlalchemy.org/en/latest/orm/composites.html) I have a `Point` class: ``` #!python class Point(object): def __init__(self, x, y): self.x = x self.y = y def __composite_values__(self): return self.x, self.y ``` I could create a mapping to a table `vertices`, which represents two points as x1/y1 and x2/y2. ``` #!python class Vertex(Base): __tablename__ = 'vertices' id = Column(Integer, primary_key=True) x1 = Column(Integer) y1 = Column(Integer) x2 = Column(Integer) y2 = Column(Integer) start = composite(Point, x1, y1) end = composite(Point, x2, y2) ``` But the problem is that I have two classes `Point` and `Line`: ``` #!python class Point(object): def __init__(self, x, y): self.x = x self.y = y class Line(object): def __init__(self, start: Point, end: Point): self.start = start self.end = end ``` I could not create a mapping to a table `Shape` like this: ``` #!python class Shape(Base): __tablename__ = 'shapes' id = Column(Integer, primary_key=True) a1 = Column(Integer) a2 = Column(Integer) b1 = Column(Integer) b2 = Column(Integer) c1 = Column(Integer) c2 = Column(Integer) d1 = Column(Integer) d2 = Column(Integer) ... line1 = composite(Line, composite(Point, a1, a2), composite(Point, b1, b2)) line2 = composite(Line, composite(Point, c1, c2), composite(Point, d1, d2)) ... ``` Maybe the example above is not good enough. But the point is that could composite be nested? |