Construct the entire tree from a SQLAlchemy adjacency list relationship

I have a class Node with a self referential mapping 'children' (backref 'parent') representing a tree in SQLAlchemy and I want to select the entire tree. If I do


then every access to node.children triggers a select. If I do a joined load


then the sql issued has an unnecessary table join since I want the entire tree (all nodes) anyways. Is there a way to do this in SA or should I just construct the tree on my own outside of SA?

задан Ilja Everilä 7 October 2019 в 18:27