如何使用小马实体定义外键
我想定义带有小马实体的外键。
如果我理解正确的话,只要命名为ID,就无需定义主键。因此,工作的主要关键是ID,我想定义与作业ID相关的食谱上的外键job_id。我尝试了必需(jobs.id),但这给出了类型错误。您对如何做有任何暗示吗?谢谢
class Jobs(db.Entity):
path = Required(str)
date = Required(str)
class Recipe(db.Entity):
job_id = Required(int) # must be foreign
path = OptionalField(str)
date = OptionalField(str)
I would like to define a foreign key with pony entities.
If I understand it right, there is no need to define a primary key as long as it is named id. so the primary key of Jobs is id, and I want to define a foreign key job_id on Recipe which is related to id of Jobs. I tried Required(Jobs.id) but this gives a type error. do you have any hint on how to do it? thank you
class Jobs(db.Entity):
path = Required(str)
date = Required(str)
class Recipe(db.Entity):
job_id = Required(int) # must be foreign
path = OptionalField(str)
date = OptionalField(str)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案。棘手的是,两种班级都必须定义关系
I found the answer. the tricky thing is that the relationship had to be defined in both classes