From: Mike Bayer Date: Mon, 29 May 2006 02:33:03 +0000 (+0000) Subject: added extra info for association object X-Git-Tag: rel_0_2_1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f5443a2b63e0fb9935b8593ca6b6e34ba0d40b0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added extra info for association object threadlocal transaction benefits from an explicit close() on the connection besides de-referencing it --- diff --git a/doc/build/content/datamapping.txt b/doc/build/content/datamapping.txt index 3722f5ac5a..32489c700d 100644 --- a/doc/build/content/datamapping.txt +++ b/doc/build/content/datamapping.txt @@ -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 diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py index a96af4ea85..e78098fa3e 100644 --- a/lib/sqlalchemy/engine/threadlocal.py +++ b/lib/sqlalchemy/engine/threadlocal.py @@ -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: