How to get a SQL Alchemy object of distinct items with filter on related objects
问题 I am trying to get a SQL Alchemy query of distinct items below filtering on related objects, the equivalent of the below query: SELECT distinct items.item_id, items.item_name FROM items INNER JOIN categories as cat on items.category_id = cat.category_id INNER JOIN stores on cat.store_id = stores.store_id WHERE store.store_id = 123 I have created the models as below with foreign keys included but when I run the query below it does not filter correctly. items_query = (db.session.query(Store,