From: Mike Bayer Date: Thu, 9 Mar 2006 15:54:44 +0000 (+0000) Subject: fixed assocaition example X-Git-Tag: rel_0_1_4~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5207bd4c5254a37cdb548df85aebf666f2e96403;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fixed assocaition example --- diff --git a/doc/build/content/datamapping.myt b/doc/build/content/datamapping.myt index 16ec1ace2b..35493247cc 100644 --- a/doc/build/content/datamapping.myt +++ b/doc/build/content/datamapping.myt @@ -734,24 +734,23 @@ INSERT INTO article_keywords (article_id, keyword_id) VALUES (:article_id, :keyw pass # mapper for KeywordAssociation - KeywordAssociation.mapper = mapper(KeywordAssociation, itemkeywords) - - # mappers for Users, Keywords - User.mapper = mapper(User, users) - Keyword.mapper = mapper(Keyword, keywords) - - # define the mapper. when we load an article, we always want to get the keywords via - # eager loading. but the user who added each keyword, we usually dont need so specify - # lazy loading for that. - m = mapper(Article, articles, properties=dict( - keywords = relation(KeywordAssociation.mapper, lazy=False, association=Keyword, + # specify "primary key" columns manually + KeywordAssociation.mapper = mapper(KeywordAssociation, itemkeywords, primary_key = [itemkeywords.c.article_id, itemkeywords.c.keyword_id], properties={ 'keyword' : relation(Keyword, lazy = False), # uses primary Keyword mapper 'user' : relation(User, lazy = True) # uses primary User mapper } - ) - ) + ) + + # mappers for Users, Keywords + User.mapper = mapper(User, users) + Keyword.mapper = mapper(Keyword, keywords) + + # define the mapper. + m = mapper(Article, articles, properties={ + 'keywords':relation(KeywordAssociation.mapper, lazy=False, association=Keyword) + } ) # bonus step - well, we do want to load the users in one shot,