On Dec 26, 2007, at 12:12 PM, Denis S. Otkidach wrote:

>
> 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:

if you have an instance which you are unsure if it already exists, you  
can add it to a session using session.save_or_update(instance).  The  
decision between INSERT and UPDATE is ultimately decided by the  
presence of an attribute on the instance called "_instance_key".  In  
most cases, this attribute is not something you need to worry about;  
if an instance has been flushed or loaded from a session, it will have  
the attribute, or if you've just constructed it and not yet persisted  
it, the attribute will not be there.  If you think you need to  
manually manipulate this attribute, perhaps you can describe your  
specific use case so that we can recommend the best way to accomplish  
it.


--~--~---------~--~----~------------~-------~--~----~
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