fix(models): resolve ambiguous foreign keys between User and InviteCode
This commit is contained in:
@@ -23,7 +23,7 @@ class User(Base):
|
||||
|
||||
profiles = relationship("Profile", back_populates="user", cascade="all, delete-orphan")
|
||||
sessions = relationship("UserSession", back_populates="user", cascade="all, delete-orphan")
|
||||
invite_codes = relationship("InviteCode", back_populates="creator", cascade="all, delete-orphan")
|
||||
invite_codes = relationship("InviteCode", back_populates="creator", foreign_keys="InviteCode.created_by", cascade="all, delete-orphan")
|
||||
invited_by_code = relationship("InviteCode", foreign_keys=[invited_by_code_id])
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class InviteCode(Base):
|
||||
created_by = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
||||
created_at = Column(DateTime, default=_utcnow)
|
||||
|
||||
creator = relationship("User", back_populates="invite_codes")
|
||||
creator = relationship("User", back_populates="invite_codes", foreign_keys=[created_by])
|
||||
registered_users = relationship("User", back_populates="invited_by_code", foreign_keys="User.invited_by_code_id")
|
||||
|
||||
|
||||
|
||||
8
test_error.py
Normal file
8
test_error.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from app.main import app
|
||||
from fastapi.testclient import TestClient
|
||||
c = TestClient(app)
|
||||
import sqlite3
|
||||
conn = sqlite3.connect('data.db')
|
||||
cur = conn.execute('SELECT id, username, invited_by_code_id FROM users')
|
||||
print(cur.fetchall())
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user