On Jul 29, 2007, at 1:11 AM, Max Ischenko wrote:
> > 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) > you should be able to session.query(WordpressPost).filter_by(status='publish').join ('categories').filter_by(slug='sitenews') --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---