SqlAlchemy Core:多次定义一对一关系

问题描述

我现在已经通过一对多实现了一个与其他三个表有关系的事件表。

events = Table(
    "events",Metadata,Column("id",Integer(),primary_key=True),Column("creator",ForeignKey(users.c.id,ondelete="SET NULL")),...
    Column("location_id",ForeignKey(locations.c.id,ondelete="SET NULL"),nullable=False),Column("activities_id",ForeignKey(activities.c.id,UniqueConstraint("location_id","id",name="event_location")
)

users = Table(
    "users",Integer,......

activities = Table(
    "activities",....

locations = Table(
    "locations",....

但是这样的连接并不满足业务逻辑。一个事件对象只能有一个创建者、位置和活动。

现在我想为所有外键字段定义一对一的关系。我找到了将 ForeignKey 定义为 primary_key=True (How to define one-to-one and many-to-many relationship using SQLAlchemy Core) 的解决方案 但是我不明白如何使用三个字段来做到这一点。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)