使用 Elixir,如何获取自引用关系的表对象来执行插入?
我将 Elixir 与 SQLite 一起使用,我想按照文档执行多次插入:
http://www.sqlalchemy.org/docs/05/sqlexpression.html#executing-multiple-statements
但是,我的 ManyToMany 关系是自引用的,我无法弄清楚从哪里获取 insert()
对象。有人可以帮忙吗?
I'm using Elixir with SQLite and I'd like to perform multiple inserts as per the docs:
http://www.sqlalchemy.org/docs/05/sqlexpression.html#executing-multiple-statements
However, my ManyToMany relationship is self-referential and I can't figure out where to get the insert()
object from. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您坚持使用 SQL Alchemy 内置的声明式风格而不是使用 Elixir,那么这可能会很容易,因为它现在可以在其中完成许多操作。然后您可以按照此处的示例操作: 多对许多
然后仔细查看添加帖子的代码,然后添加与该帖子相关的关键字。您可以在相关表中完成多次插入 - 维护多对多关系的表:
It might be easy if you just stick with SQL Alchemy's built in Declarative style instead of using Elixir as much of what it does is now doable in there. Then you can follow the example here: Many to Many
Then look very closely at the code where a post is added and then keywords related to that post are added. You get multiple inserts done for you into the relator table - the one that maintains the many to many relationship: