Source code for election_day.models.election_compound.relationship

from __future__ import annotations

from onegov.core.orm import Base
from sqlalchemy import ForeignKey
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import relationship
from sqlalchemy.orm import Mapped
from uuid import uuid4
from uuid import UUID


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from onegov.election_day.models import ElectionCompound


[docs] class ElectionCompoundRelationship(Base): """ A relationship between election compounds. """
[docs] __tablename__ = 'election_compound_relationships'
#: Identifies the relationship.
[docs] id: Mapped[UUID] = mapped_column( primary_key=True, default=uuid4 )
#: The source election compound ID.
[docs] source_id: Mapped[str] = mapped_column( ForeignKey('election_compounds.id', onupdate='CASCADE') )
#: The target election compound ID.
[docs] target_id: Mapped[str] = mapped_column( ForeignKey('election_compounds.id', onupdate='CASCADE'), primary_key=True )
#: The source election compound.
[docs] source: Mapped[ElectionCompound] = relationship( foreign_keys=[source_id], back_populates='related_compounds' )
#: The target election compound.
[docs] target: Mapped[ElectionCompound] = relationship( foreign_keys=[target_id], back_populates='referencing_compounds' )
#: the type of relationship
[docs] type: Mapped[str | None]