Marco Mariani wrote:
> 
> Simon Willison wrote:
> > I've got a bit of code that looks like this:
> >
> > session = get_session()
> > session.save(obj)
> > session.flush()
> >   
> You can see what's going to be inserted/updated/deleted by 
> accessing session.new, session.dirty, session.deleted
> 
> http://www.sqlalchemy.org/docs/unitofwork.myt
> 
> > What's the best way of telling if obj has been newly 
> created (INSERT) 
> > or merely updated (UPDATE)? I tried just checking for 
> "obj.id is None"
> > but I can't garauntee that my primary key is called 'id'.
> I would hope so! :-))
> 

If you are wanting to know _after_ the session.flush(), I don't think
session.new/dirty/deleted will help you. Also, your primary key will be
read back from the database immediately after INSERT, so it won't be
None. Between, the save and the flush, "obj in session.new" should do
the job.

Simon

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