diff --git a/src/organisation/models.py b/src/organisation/models.py index 7ed5d91..ceae8f7 100644 --- a/src/organisation/models.py +++ b/src/organisation/models.py @@ -7,6 +7,7 @@ Models: - OrgUsers: org_id[fk][cpk], user_id[fk][cpk], is_admin """ from sqlalchemy import Column, Integer, String, ForeignKey, JSON +from sqlalchemy.orm import relationship from src.database import Base @@ -25,6 +26,12 @@ class Organisation(Base): security_contact_id = Column(Integer, ForeignKey("contact.id")) owner_contact_id = Column(Integer, ForeignKey("contact.id")) + users = relationship( + "User", + secondary="orgusers", + back_populates="organisations" + ) + class OrgUsers(Base): __tablename__ = "orgusers" diff --git a/src/user/models.py b/src/user/models.py index 89801d5..7bce630 100644 --- a/src/user/models.py +++ b/src/user/models.py @@ -5,6 +5,7 @@ Models: - User - id[pk], email, first_name, last_name, oidc_id """ from sqlalchemy import Column, Integer, String +from sqlalchemy.orm import relationship from src.database import Base @@ -17,3 +18,9 @@ class User(Base): first_name = Column(String) last_name = Column(String) oidc_id = Column(String, index=True, unique=True) + + organisations = relationship( + "Organisation", + secondary="orgusers", + back_populates="users" + )