4 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Eager loading self r...
FromSent OnAttachments
Koen Bok23 Mar 2007 09:14 
Andreas Jung23 Mar 2007 09:24 
Koen Bok23 Mar 2007 09:53 
Michael Bayer23 Mar 2007 10:36 
Subject:[sqlalchemy] Re: Eager loading self referential mapper
From:Michael Bayer (mike@zzzcomputing.com)
Date:03/23/2007 10:36:39 AM
List:com.googlegroups.sqlalchemy

its not theoretically impossible, but it is theoretically ridiculously complicated to do automatically, and also would have to limit the depth arbitrarily to one or two levels (which means, someone wants level 5 off their eager loader, then they come back to complain). each level of nodes for an adjacency-list relationship requires a distinct self-join. each self-join would need to be aliased too, which then gets pretty complicated when that self-join is injected into a larger mapping of enclosing eager loaders, etc. plus all the code that right now knows "stop eager loading when we come back to our own mapper" now becomes a lot more complicated, since now we are counting levels and stuff like that. add onto that the really insane self-joins that already arise with polymorphic mappings, id be fixing bugs in that code for ten years. the queries are way too huge. not to mention the efficiency issues that start to arise when you start self-joining too much.

So, if you really need to load alot of self-ref nodes in one query, you query all the nodes yourself and then attach them. thats what the example "examples/adjacencytree/byroot_tree.py" illustrates.

On Mar 23, 2007, at 12:14 PM, Koen Bok wrote:

Could anyone please explain me a little why self referantial mappers cannot be eager-loading. Is this not yet integrated in SQLAlchemy or theoratically impossible or impractical?

Ciao