hi
is there an official way to undo creation and setup of a complex 
object? esp. its relations...

lets say there is A with references and collections and many2manys.

def setup():
 my_b = query(B).first()
 my_X = query(X).first()

 a = A()                #in case of creating_new
 a.name = 'abc'
 a.b_ref = my_b
 a.c_ref = C(name=cc)
 a.d_ref = D(name=dd)
 a.assoc_X.append( my_X) 
 return a

and now the above has to be cancelled.

we have invented this way to do it, but it is not at all obvious (yes 
there is only one session staying):

def cancel( obj, creating_new =True):
  updating = not creating_new
  if updating:
    session.expire( obj)
  else:
    for k in references_created_new( obj):  #should walk c_ref, d_ref
        session.expunge( getattr(obj, k) )
    session.expunge( obj)

the test is that after 
a=setup()
cancel( a, True)
session.flush() should do nothing.

i could not make it with anything less than this to work. maybe 
there's even more to it...
it's not clear in references_created_new() how to distinguish the refs 
to existing persistent objects from just-created not-yet-persistent 
ones - maybe checking in session.new or what..

ciao
svilen

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