SQLAlchemy: eager loading of more than one relationship

Each Answer to this Q is separated by one/two green lines.

I want to query this structure:

A -> B
B -> C
B -> D

what’s the syntax to do this with the Load interface, the documentation is not very clear on this (http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#sqlalchemy.orm.joinedload). All I see is how to do:

A -> B
B -> C
C -> D

Given the query:


How do I go backward in the chain to specify the second relationship on B (B.d)?

Just add another .options(...) with a new relationship path:

q = (

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .