On Sep 17, 2008, at 3:35 AM, Alec Thomas wrote:
> > From the example here: > > http://www.sqlalchemy.org/docs/04/documentation.html#datamapping_manytomany > > How can i construct a query that will return the keywords for posts > from > a particular user? > > I'd expect this to work: > > session.query(Keyword).join(BlogPost.keywords) \ > .filter(BlogPost.author == wendy).all() > > and it does with 0.5, but not with 0.4.7p1 :( > > > I can make this work by adding a backref on the keywords relation and > joining against it, but in "real life" (ie. my application) I'd like > to avoid this given the number of tables that link to it. > > Any ideas? the backref is the standard approach to giving sqlalchemy a "path" to join from Y to X, without spelling out the join condition yourself. Theres no reason at all you cant put one of these there - they dont impact performance, they dont load unnecessarily, etc. if you'd like to use a sql.join() object, which is the only other option in 0.4, say: query (Keyword ).select_from (keywords .join (post_keywords).join(posts_table)).filter(BlogPost.author==wendy).all() the join() expressions there *should* work without an ON clause given. Its a little weird that joining from Keyword along BlogPost.keywords works in 0.5, that wasn't the intended usage there but I guess I can see how that's working. basically, either have relation() present (a backref is just a kind of relation()) so SQLA knows where to go, or spell out the join explicitly. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---