I'd like to construct Python object and replace it into DB, i.e. it
should be INSERTed with certain identifier (primary key) if it doesn't
exist or UPDATed otherwise. According to documentation that's what
merge is for:

> merge() on the other hand is a little like update(), except it creates a copy 
> of the given instance
> in the session, and returns to you that instance; the instance you send it 
> never goes into the
> session. merge() is much fancier than update(); it will actually look to see 
> if an object with the
> same primary key is already present in the session, and if not will load it 
> by primary key. Then,
> it will merge the attributes of the given object into the one which it just 
> located.

But this doesn't help: it does INSERT causing primary key constrain
failure when there is no object with such identifier in the session,
or FlushError ("New instance ... with identity key conflicts with
persistent instance ...") when such object was previously loaded. Do I
understand merge() wrong? Is there a proper was to replace object?

BTW, replacing worked fine with SA 0.3 without need to handle it
specially: just save() + flush() calls.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to