Trying to filter by an intermediate table <p>I'm trying to do this query</p> <pre><code>subsidiaries = self.con.query(Subsidiary)\ .options(joinedload(Subsidiary.commerce)\ .joinedload(Commerce.commerce_tags))\ .filter(CommerceTag.tag_id == id) </code></pre> <p>But it doesn't work, so to explain:</p> <p>The relationship between tables are:</p> <p><a href="https://i.stack.imgur.com/aH8Su.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aH8Su.png" alt="Relationship"></a></p> <p>I just want to obtain all the subsidiaries of all the commerces that has an specific tag, i want to do it with Subsidiary has the base class (i know that if i use Commerce it will be more easier), the reason is 'cause i convert it to a json value with the next format:</p> <pre><code>"subsidiaries": [ { "id": 1, "name": "some_name", "commerce": { "id": 1, "name": "Commerce Name" } } ] </code></pre> <p>Well, i can do the query with Commerce has base class, but i think that maybe iterating the commerces to obtain the subsidiaries is more expensive that doing it in the query.</p> <p>I don't want to load CommerceTag but i had it in joinedload 'cause it doesn't work with Join method.</p> <p>I need some help to do this :(</p>