더북(TheBook)

파이썬(/appserver/apps/account/models.py)

# 생략
from sqlmodel import SQLModel, Field, Relationship, func, Column, AutoString

class User(SQLModel, table=True):
    __tablename__ = "users"
    # 생략

    oauth_accounts: list[OAuthAccount] = Relationship(back_populates="user")  # ①
class OAuthAccount(SQLModel, table=True):
    __tablename__ = "oauth_accounts"
    # 생략

    user_id: int = Field(foreign_key="users.id")
    user: User = Relationship(back_populates="oauth_accounts")  # ②

User 모델의 oauth_accounts 모델 필드에 있는 Relationshipback_populates="user"를 추가하고, 같은 방식으로 OAuthAccountuser 모델 필드에도 반영했습니다(①).

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.