I thought for a while that what you were doing couldnt work right now.
this is because a join to the KeywordAssociation object doesnt know
anything about the next join to Keyword.  but then actually, i realized
you could do it, but it does require that the relation from
keywordassociation to keyword is eager.  a little bit of query watching
helps as well in figuring something like this out.  Also, I didnt make
a big deal out of this in the release but the "association" keyword
argument isnt really needed anymore, all it does is ensure that the
cascade has "delete"/"delete-orphan" now.

heres a diff against your test to illustrate:

--- foo.py      2006-10-29 12:01:13.000000000 -0500
+++ test.py     2006-10-29 11:58:23.000000000 -0500
@@ -39,11 +39,13 @@
                 return "KeywordAssociation itemid=%d keyword=%s
data=%s" % (self.item_id, repr(self.keyword), self.data)

         mapper(Keyword, keywords)
+
         mapper(KeywordAssociation, item_keywords, properties={
-            'keyword':relation(Keyword, lazy=False)
-        }, primary_key=[item_keywords.c.item_id,
item_keywords.c.keyword_id], order_by=[item_keywords.c.data])
+            'keyword':relation(Keyword, lazy=False,
order_by=[keywords.c.name])
+        }, primary_key=[item_keywords.c.item_id,
item_keywords.c.keyword_id])
+
         mapper(Item, items, properties={
-            'keywords' : relation(KeywordAssociation,
association=Keyword, order_by=[keywords.c.name], lazy=True,
cascade="all,delete-orphan")
+            'keywords' : relation(KeywordAssociation, lazy=True,
order_by=None)
         })

     def tearDown(self):
@@ -60,8 +62,9 @@
         item1.keywords.append(KeywordAssociation(Keyword('blue'),
'blue_assoc'))
         sess.save(item1)
         sess.flush()
-
+        sess.clear()
         l = sess.query(Item).select()
+
         names = [k.keyword.name for k in l[0].keywords]
         self.assert_(names == ['blue','red'])

@@ -72,7 +75,7 @@
         item1.keywords.append(KeywordAssociation(Keyword('blue'),
'blue_assoc'))
         sess.save(item1)
         sess.flush()
-
+        sess.clear()
         l = sess.query(Item).options(eagerload('keywords')).select()
         names = [k.keyword.name for k in l[0].keywords]
         self.assert_(names == ['blue','red'])


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sqlalchemy
-~----------~----~----~----~------~----~------~--~---

Reply via email to