diff --git a/api/kiwi_vpn_api/db/models.py b/api/kiwi_vpn_api/db/models.py index 633e78a..f9b6afa 100644 --- a/api/kiwi_vpn_api/db/models.py +++ b/api/kiwi_vpn_api/db/models.py @@ -24,10 +24,10 @@ class User(ORMBaseModel): "UserCapability", lazy="joined", cascade="all, delete-orphan" ) certificates: list[Certificate] = relationship( - "Certificate", lazy="select" + "Certificate", lazy="select", back_populates="owner" ) distinguished_names: list[DistinguishedName] = relationship( - "DistinguishedName", lazy="select" + "DistinguishedName", lazy="select", back_populates="owner" ) @classmethod @@ -69,6 +69,10 @@ class DistinguishedName(ORMBaseModel): email = Column(String) common_name = Column(String, nullable=False) + owner: User = relationship( + "User", lazy="joined", back_populates="distinguished_names" + ) + UniqueConstraint( country, state, @@ -96,3 +100,7 @@ class Certificate(ORMBaseModel): distinguished_name: DistinguishedName = relationship( "DistinguishedName", lazy="joined" ) + + owner: User = relationship( + "User", lazy="joined", back_populates="certificates" + )