如何在SQLAlchemy或SqlSoup ORM中自动反映表关系?
如何告诉 SQLAlchemy 自动将基本外键引用反映为对其他 ORM 对象而不是整数字段的引用?
在 SQLAlchemy 中,它是 SQLAlchemy。 sqlalchemy.org/docs/orm/extensions/sqlsoup.html#relationships">SqlSoup,表列会自动反映,关系可以手动定义:
class User(Base):
__table__ = metadata.tables['users']
loan = relation(Loans)
...
You can define relationships on SqlSoup classes:
>>> db.users.relate('loans', db.loans)
How do I tell SQLAlchemy to automatically reflect basic Foreign Key references as references to other ORM objects and not integer fields?
In both SQLAlchemy and it's SqlSoup, table columns are reflected automatically and relations can be defined manually:
class User(Base):
__table__ = metadata.tables['users']
loan = relation(Loans)
...
You can define relationships on SqlSoup classes:
>>> db.users.relate('loans', db.loans)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个魔法)
适用于简单的 FK 关系,并且没有数据库方案
Try this magic )
Works for simple FK relations, and without db schemes