Skip to content

Class tigrbl.orm.mixins.hierarchy.Contained

tigrbl.orm.mixins.hierarchy.Contained

parent_id

parent_id()
Source code in tigrbl/orm/mixins/hierarchy.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@declared_attr
def parent_id(cls) -> Mapped[UUID]:
    if not hasattr(cls, "parent_table"):
        raise AttributeError("subclass must set parent_table")
    spec = ColumnSpec(
        storage=S(
            type_=PgUUID(as_uuid=True),
            fk=ForeignKeySpec(target=f"{cls.parent_table}.id"),
            nullable=False,
        ),
        field=F(py_type=UUID),
        io=CRUD_IO,
    )
    return acol(spec=spec)