the cleanest way is to leave the old entity alone and to create a new
one using a copy constructor:

class MyEntity(object):
    def new_version(self):
        return MyEntity(version = self.version + 1, foo=self.foo,
bar=self.bar)

To "force" an object from an UPDATE back to an INSERT, which is more
about SQLA internals and is less guaranteed to work in future versions
(this is the 0.5 version), do this:

from sqlalchemy.orm.attributes import instance_state

session.expunge(myentity)
del instance_state(myentity).key
session.add(myentity)


On Oct 6, 9:58 am, Joril <[EMAIL PROTECTED]> wrote:
> Hi everyone!
> I'm trying to implement data logging with SQLAlchemy.. That is,
> whenever someone updates a persisted entity, generate a new record and
> then mark the old one as such.
>
> My problem right now is that if I load an entity from the DBMS, modify
> it and then try to save it again, I have to tell SQLA that the entity
> needs to be INSERTed, not UPDATEd.. I tried zeroing entity.id and
> entity.version, but it still tries an UPDATE.. How do I "trick" SQLA
> into thinking it's a new entity?
>
> Many thanks for your time!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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