I'm sure I'm missing something simple here, and any pointers in the right direction would be greatly appreciated.

Take for instance the following code:

session = Session()
parents = session.query(Parent).options(joinedload(Parent.children)).all()
session.close()

print parents[0].children  # This works
print parents[0].children[0].parent  # This gives a lazy loading error

Adding the following loop before closing the session works (and doesn't hit the DB):

for p in parents:
  for c in p.children:
    c.parent

As far as I can tell, the mapping is correct since:

* It all works fine if I leave the session open
* If I don't use joinedload, and leave the session open it lazyloads correctly

I'm surprised that:

* It doesn't set both sides of the relation, considering it apparently knows about them * It complains that the session is closed despite not actually requiring an open session (no SQL is sent to the DB for c.parent)

These apprent "do-nothing" loops are starting to clutter the code. There must be a better way.

Thanks

Jon

--
Jon Siddle, CoreFiling Limited
Software Tools Developer
http://www.corefiling.com
Phone: +44-1865-203192

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to