From 941b2c600163b03e68a40f76981cb492c80f0f43 Mon Sep 17 00:00:00 2001 From: "XPS\\Micro" Date: Sun, 8 Feb 2026 18:35:54 +0100 Subject: [PATCH] fix: Add explicit primaryjoin to UserContainer relationships for SQLAlchemy ambiguity resolution --- models.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/models.py b/models.py index 95eafcb..e0f9a6e 100644 --- a/models.py +++ b/models.py @@ -152,9 +152,14 @@ class UserContainer(db.Model): blocked_at = db.Column(db.DateTime, nullable=True) blocked_by = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='SET NULL'), nullable=True) - # Relationships - user = db.relationship('User', foreign_keys=['user_id'], back_populates='containers') - blocker = db.relationship('User', foreign_keys=['blocked_by']) + # Relationships (explicit primaryjoin wegen mehrerer FKs zu User) + user = db.relationship('User', + foreign_keys=['user_id'], + primaryjoin='UserContainer.user_id==User.id', + back_populates='containers') + blocker = db.relationship('User', + foreign_keys=['blocked_by'], + primaryjoin='UserContainer.blocked_by==User.id') # Unique: Ein User kann nur einen Container pro Typ haben __table_args__ = (