Suppose I have the following tables:
Articles
with fieldsarticle_id
,title
Tags
with fieldstag_id
,name
ArticleTags
with fieldsarticle_id
,tag_id
And I wish to find all articles that have a given tag. How do I create this complicated join in SQLAlchemy?
In SQL it would look like:
SELECT a.article_id, a.title FROM Articles AS a
JOIN ArticleTags AS at ON a.article_id = at.article_id
JOIN Tags AS t ON at.tag_id = t.tag_id
WHERE t.name = 'tag_name'
I can't figure out how to do it in SQLAlchemy. I am using ArticleTags
as "secondary" table only and I can't figure out how to involve it in the JOIN.
Can anyone help?
Thanks, Boda Cydo.