forked from sr2/cloud-api
fix: ty compliant & issues from change to mapped columns
This commit is contained in:
parent
55927946c7
commit
58e7ae6c5c
31 changed files with 271 additions and 254 deletions
|
|
@ -13,6 +13,7 @@ Models:
|
|||
- owner_contact_rel: ORM relationship to Contact with owner_contact FK
|
||||
- OrgUsers: org_id[FK][PK], user_id[FK][PK]
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
|
|
@ -30,15 +31,17 @@ class Organisation(CustomBase):
|
|||
intake_questionnaire: Mapped[dict[str, Any] | None]
|
||||
|
||||
root_user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
|
||||
billing_contact_id: Mapped[int] = mapped_column(ForeignKey("contact.id"))
|
||||
security_contact_id: Mapped[int] = mapped_column(ForeignKey("contact.id"))
|
||||
owner_contact_id: Mapped[int] = mapped_column(ForeignKey("contact.id"))
|
||||
|
||||
user_rel = relationship(
|
||||
"User", secondary="orgusers", back_populates="organisation_rel"
|
||||
billing_contact_id: Mapped[int] = mapped_column(ForeignKey("contact.id"), nullable=True)
|
||||
security_contact_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("contact.id"), nullable=True
|
||||
)
|
||||
owner_contact_id: Mapped[int] = mapped_column(ForeignKey("contact.id"), nullable=True)
|
||||
|
||||
group_rel = relationship("Group", back_populates="org_rel")
|
||||
user_rel = relationship("User", secondary="orgusers", back_populates="organisation_rel")
|
||||
|
||||
group_rel = relationship(
|
||||
"Group", back_populates="org_rel", cascade="all, delete-orphan"
|
||||
)
|
||||
root_user_rel = relationship("User", foreign_keys="Organisation.root_user_id")
|
||||
|
||||
billing_contact_rel = relationship(
|
||||
|
|
@ -56,8 +59,9 @@ class Organisation(CustomBase):
|
|||
)
|
||||
|
||||
@property
|
||||
def root_user_email(self):
|
||||
return self.root_user_rel.email if self.root_user_rel else None
|
||||
def root_user_email(self) -> str:
|
||||
return self.root_user_rel.email if self.root_user_rel else ""
|
||||
|
||||
|
||||
class OrgUsers(CustomBase):
|
||||
__tablename__ = "orgusers"
|
||||
|
|
@ -65,4 +69,6 @@ class OrgUsers(CustomBase):
|
|||
org_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("organisation.id", ondelete="CASCADE"), primary_key=True
|
||||
)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("user.id", ondelete="CASCADE"), primary_key=True)
|
||||
user_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("user.id", ondelete="CASCADE"), primary_key=True
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue