diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index 14e1c7ad..351907a8 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -1,11 +1,12 @@ from uuid import uuid4 from flask import current_app as app +from flask import g from flask_login import UserMixin from sqlalchemy import BigInteger, Boolean, Column, Sequence from sqlalchemy.dialects.postgresql import UUID from sqlalchemy_utils import EmailType, PasswordType -from teal.db import URL, IntEnum +from teal.db import CASCADE_OWN, URL, IntEnum from ereuse_devicehub.db import db from ereuse_devicehub.resources.enums import SessionType @@ -122,18 +123,24 @@ class Session(Thing): class SanitizationEntity(Thing): - id = Column(BigInteger, primary_key=True) - company_name = Column(db.String, nullable=True) - location = Column(db.String, nullable=True) - logo = Column(db.String, nullable=True) - logo = Column(URL(), nullable=True) - responsable_person = Column(db.String, nullable=True) - supervisor_person = Column(db.String, nullable=True) - user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id)) + id = db.Column(BigInteger, primary_key=True) + company_name = db.Column(db.String, nullable=True) + location = db.Column(db.String, nullable=True) + # logo = db.Column(db.String, nullable=True) + logo = db.Column(URL(), nullable=True) + responsable_person = db.Column(db.String, nullable=True) + supervisor_person = db.Column(db.String, nullable=True) + user_id = db.Column( + db.UUID(as_uuid=True), + db.ForeignKey(User.id), + default=lambda: g.user.id, + ) user = db.relationship( User, - backref=db.backref('sanitization_entity', lazy=True, collection_class=set), - collection_class=set, + backref=db.backref( + 'sanitization_entity', lazy=True, uselist=False, cascade=CASCADE_OWN + ), + primaryjoin=user_id == User.id, ) def __str__(self) -> str: