Skip to content

Commit

Permalink
用户表不支持外键
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Sep 19, 2023
1 parent 941b983 commit 8b79339
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/plugins/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
from sqlalchemy import DateTime, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

plugin_data = get_plugin_data()
plugin_data.use_global_registry()

Model = plugin_data.Model
Model = get_plugin_data().Model


class User(Model):
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(255))
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)

binds: Mapped[list["Bind"]] = relationship(back_populates="auser")
binds: Mapped[list["Bind"]] = relationship(
back_populates="auser", foreign_keys="[Bind.aid]"
)
"""当前绑定的平台"""
bind: Mapped["Bind"] = relationship(back_populates="buser")
bind: Mapped["Bind"] = relationship(
back_populates="buser", foreign_keys="[Bind.bid]"
)
"""初始时绑定的平台"""


Expand All @@ -39,12 +40,6 @@ class Bind(Model):
"""初始时绑定的账号"""


User.binds = relationship(
Bind, uselist=True, back_populates="auser", foreign_keys=[Bind.aid]
)
User.bind = relationship(Bind, back_populates="buser", foreign_keys=[Bind.bid])


@dataclass
class UserSession:
session: Session
Expand Down

0 comments on commit 8b79339

Please sign in to comment.