Having an adjacency list tree (actually, in my case it's a DAG) model it's easy to write a recursive CTE which returns a list of the nodes together with their level or path from the root, and applying filters is also no problem. However, I couldn't find in the documentation and previous discussions any information about how to fill a proper hierarchy this way? I mean a kind of eager loading, like root.children[i].children[i]..., with arbitrary number of levels. All the data required to build this hierarchy is present in the CTE results, so it should be possible. Of course, in a simple case I could just use joinedload with the depth equal to the longest path length, but adding some filtering requires explicit aliased joins with contains_eager which can greatly increase the code complexity: in my case I have many-to-many relationships as the structure is a DAG (not a tree), and I also need to load two more relationship (like root.children[i].child.some_properties) which I join (and alias, and add contains_eager for it) for each level.
What's the preferred solution for such problems? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
