]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added extra info for association object
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 May 2006 02:33:03 +0000 (02:33 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 May 2006 02:33:03 +0000 (02:33 +0000)
threadlocal transaction benefits from an explicit close() on the connection besides de-referencing it

doc/build/content/datamapping.txt
lib/sqlalchemy/engine/threadlocal.py

index 3722f5ac5a57757c98c7094049fbd3b7ba4e0e22..32489c700dbc22357420aabd0ef4b4eada93094a 100644 (file)
@@ -785,3 +785,26 @@ Many to Many can also be done with an association object, that adds additional i
         for k in a.keywords:
             if k.keyword.name == 'jacks_stories':
                 print k.user.user_name
+
+Keep in mind that the association object works a little differently from a plain many-to-many relationship.  Members have to be added to the list via instances of the association object, which in turn point to the associated object:
+
+    {python}
+    user = User()
+    user.user_name = 'some user'
+    
+    article = Article()
+    
+    assoc = KeywordAssociation()
+    assoc.keyword = Keyword('blue')
+    assoc.user = user
+    
+    assoc2 = KeywordAssociation()
+    assoc2.keyword = Keyword('green')
+    assoc2.user = user
+    
+    article.keywords.append(assoc)
+    article.keywords.append(assoc2)
+    
+    session.flush()
+    
+    
\ No newline at end of file
index a96af4ea85ece881f0cffc5342886ad7b50d33dd..e78098fa3ecad3f1c4beb43db2f1da53f580c460 100644 (file)
@@ -22,6 +22,7 @@ class TLSession(object):
         self.__tcount += 1
     def reset(self):
         try:
+            self.__transaction.close()
             del self.__transaction
             del self.__trans
         except AttributeError: