From ac6e506486f711fab8c475fd56a83809bd2eb81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Wed, 23 Mar 2022 15:30:22 +0000 Subject: [PATCH] back population --- api/kiwi_vpn_api/db/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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" + )