具有关系的 SQLAlchemy 克隆表行 [英] SQLAlchemy clone table row with relations

查看:21
本文介绍了具有关系的 SQLAlchemy 克隆表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继此问题SQLAlchemy:分离对象的修改.

这使得对象的副本很好,但它失去了原始对象具有的任何多对多关系.有没有办法复制对象和任何多对多关系?

This makes a copy of the object fine, but it loses any many-to-many relationships the original object had. Is there a way to copy the object and any many-to-many relationships as well?

干杯!

推荐答案

我通过遍历对象图并按照描述对图中的每个对象执行 expunge()、make_transient() 和 id = None 步骤来实现此目的在 SQLAlchemy:分离对象的修改中.

I got this to work by walking the object graph and doing the expunge(), make_transient() and id = None steps on each object in the graph as described in SQLAlchemy: Modification of detached object.

这篇关于具有关系的 SQLAlchemy 克隆表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆