[sqlalchemy] How to avoid double join on the same table?

2012-11-23 Thread Kevin Q
suppose I have the following tables (in pseudo-code) User: * userid * name Thing * thingid * name * userid Thing.user = relation(User, User.userid==Thing.userid) Now, If I have the following query: query = session.query(Thing).option(joinedload('user')).join(User).filter(User.name ==

[sqlalchemy] Detect whether a query already has a join on a table?

2012-11-21 Thread Kevin Q
I want to avoid double joining on the same table. I know query._from_obj is where the query stores the join elements. However, it's not there if the join is from query.options(joinedload('some_relation')). For example, I have the following table relations: User: * userid * name Thing *