From 5207bd4c5254a37cdb548df85aebf666f2e96403 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 9 Mar 2006 15:54:44 +0000 Subject: [PATCH] fixed assocaition example --- doc/build/content/datamapping.myt | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) 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, -- 2.47.2