On 5/22/15 1:10 AM, c.bu...@posteo.jp wrote:
I opened a questions with example (pseudo) code on stackoverflow for
that.
<http://stackoverflow.com/questions/30287042/how-to-use-make-transient-to-duplicate-an-sqlalchemy-mapped-object>
I know the question how to duplicate or copy a SQLAlchemy mapped object
was asked a lot of times. The answer always depends on the needs or how
"duplicate" or "copy" is interpreted. This is a specialized version of
the question because I got the tip to use make_transient() for that.
But I have some problems with that. I don't really know how to handle
the primary key (PK) here. In my use cases the PK is always
autogenerated by SQLA (or the DB in background). But this doesn't
happen with a new duplicated object.
if you copy an object to transient, now instance_state.key is gone, next
step is erase the primary key column-holding attributes, such as
myobject.id = None. object on flush will have no PK value and
autoincrement will be used instead.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.