Skip to content

Migrating from joinedload_all to Avoid Duplicate Joins in SQLAlchemy #11356

Discussion options

You must be logged in to vote

that's just one option cancelling the other out - an idiosyncrasy in 1.3 is causing the joinedload_all() version to place the contains_eager at a higher priority. reverse the order for both and put the contains_eager() last, so it overrides whatever is there for "bs":

q1 = s.query(A).join(B).options(joinedload_all("bs.cs"), joinedload_all("bs.ds")).options(contains_eager('bs'))

q2 = s.query(A).join(B).options(joinedload("bs").joinedload("cs"), joinedload("bs").joinedload("ds")).options(contains_eager('bs'))

now you get the same query.

Bigger picture you should not use two options that match the same path. if you want to ignore a path token, use defaultload() like this:

q2 = s.query(A).jo…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
8 replies
@mutazzuhairi
Comment options

@zzzeek
Comment options

@mutazzuhairi
Comment options

@zzzeek
Comment options

Answer selected by mutazzuhairi
@mutazzuhairi
Comment options

@zzzeek
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants