여기에서 주의할 점이 있습니다. OAuthAccount 모델을 User 모델보다 아래에 배치하는 경우 User 모델의 oauth_accounts 모델 필드는 다음과 같이 자료형 각주로 변경해야 합니다.
파이썬(/appserver/apps/account/models.py)
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")
달라진 점은 list[OAuthAccount]가 list["OAuthAccount"]처럼 OAuthAccount를 문자열로 표기한 것입니다(①). 파이썬은 자료형 각주에서 자료형을 문자열로 표기하면 해당 자료형(클래스)을 지연 평가(lazy evaluation)하는데, 이를 파이썬에서는 문자열 각주(annotation) 또는 전방 참조(forward reference)라고 합니다. 순환 참조를 해결하거나 아직 정의되지 않은 자료형을 참조할 때 사용하는 방식입니다.