Alan Franzoni ha scritto:
[italian mode]
Come va Manlio? Ci sente anche qui alla fine :-) io per la fine dell'anno dovrei riuscire a finire il progetto su cui sto lavorando e potrĂ² riprendere finalmente il mio lavoro anche con python.it <http://python.it>!
[/italian mode]


Hi Alan!

1st:
In order to use a transaction with a pre-existent connection, you should bind the session to the connection. This can be done by creating the session this way:

sess = create_session(bind_to=conn)

This is useful if you want to work both with the SQL layer and with the ORM layer of SA. If you just want to use the ORM layer (like you appear to do), forget the 'conn' and 'trans' in your code, and just do

sess = create_session()
trans = sess.create_transaction()

and just use trans.rollback() or trans.commit() in your code.



In my code I use:
trans = conn.begin()
sess = create_session(bind_to=conn)

The example posted was wrong, sorry.


2nd:
If I got what you want: you want to be able to remove the 'B' instance from the 'A' instance without removing the 'A' object from the db, right?

Right.

session.delete() is the way to go, because that's the way you remove objects using the SA ORM.

Yes, I just discovered this by myself.

The problem is that it requires the explicit use of the session.
In my case this means that I can not delete the object inside a method of my class.

class A(object):
   def enableB(enable=True):
      if enable:
         self.b = B(...)
      else:
         del self.b


Not a big problem, however.



Thanks and regards  Manlio Perillo

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