Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLAlchemy clone table row with relations

Tags:

sqlalchemy

Following on from this question SQLAlchemy: Modification of detached object.

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?

Cheers!

like image 534
Ben Kilah Avatar asked Nov 21 '13 04:11

Ben Kilah


1 Answers

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.

like image 172
David K. Hess Avatar answered Nov 01 '22 21:11

David K. Hess