Hello, I'm using SQLAlchemy to access my WordPress database and I need to query posts from particular category.
There is a many-to-many mapping between wp_posts and wp_categories table, throught wp_post2cat table. I was able to come up with the following code: cats = self.meta.tables['wp_categories'] posts = self.meta.tables['wp_posts'] post2cat = self.meta.tables['wp_post2cat'] q = self.session.query(WordpressPost) q = q.filter(WordpressPost.c.status=='publish') q = q.filter(WordpressCategory.c.slug=='sitenews') q = q.filter(post2cat.c.post_id==posts.c.ID) q = q.filter(post2cat.c.category_id==cats.c.cat_ID) It works correctly but seems too verbose to me. Basically I do two joins by hand. I suspect SQLAlchemy can do this for me, just can't figure out how. Help, please? Max. P.S.: I have: mapper(WordpressCategory, wp_categories_tbl , properties={ 'id' : wp_categories_tbl.c.cat_ID, ... }) mapper(WordpressPost, wp_posts_tbl, properties={ 'id' : wp_posts_tbl.c.ID, ... 'categories': relation(WordpressCategory, secondary=wp_post2cat_tbl), }) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---