[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!
[/italian mode]

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.

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?
session.delete() is the way to go, because that's the way you remove objects
using the SA ORM. And you must pull out the 'cascade='all'' from the 'a'
relation, because if you instruct SA to do this, it will try to remove its
related object (the 'A' instance), which is not what you wont.

Look at this and tell me if it produces the result you would expect:

mapper(A, a)
mapper(
   B, b,
   properties={
       'a': relation(
           A, backref=backref('b', lazy=False, uselist=False,
                              cascade='all'),
           uselist=False  )
       }
   )



sess = create_session()
o = A('1', '2')
o.b = B(o.x, o.y, '3')

sess.save(o)
sess.flush()
sess.expunge(o)
sess.clear()
del o

o = sess.query(A).get_by(x="1", y="2")
print o.b.z
sess.delete(o.b)
sess.flush()
sess.close()

print o.b
s = a.select()
print s.execute().fetchall()



--
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E

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