jason kirtland  committed 280907b

Fixed assoc proxy examples [ticket:1191]

  • Participants
  • Parent commits 9b46cbd

Comments (0)

Files changed (1)

File doc/build/content/plugins.txt

         Column('id', Integer, primary_key=True),
         Column('name', String(64)),
     keywords_table = Table('keywords', metadata,
         Column('id', Integer, primary_key=True),
         Column('keyword', String(64))
     # [<__main__.Keyword object at 0xb791ea0c>]
     # 'cheese inspector'
-    print [keyword.keyword for keyword in u._keywords]
+    print [keyword.keyword for keyword in]
     # ['cheese inspector']
 With ``association_proxy`` you have a "view" of the relation that contains just the `.keyword` of the related objects.  The proxy is a Python property, and unlike the mapper relation, is defined in your class:
     # users_table and keywords_table tables as above, then:
+    def get_current_uid():
+        """Return the uid of the current user."""
+        return 1  # hardcoded for this example
     userkeywords_table = Table('userkeywords', metadata,
         Column('user_id', Integer, ForeignKey(""), primary_key=True),
         Column('keyword_id', Integer, ForeignKey(""), primary_key=True),
             self.user = user
             self.keyword = keyword
-    mapper(User, users_table, properties={
-        'user_keywords': relation(UserKeyword)
-    })
+    mapper(User, users_table)
     mapper(Keyword, keywords_table)
     mapper(UserKeyword, userkeywords_table, properties={
-        'user': relation(User),
+        'user': relation(User, backref='user_keywords'),
         'keyword': relation(Keyword),
     user = User('log')
     kw1  = Keyword('new_from_blammo')