Greetengs !!
I'm having trouble getting a list from a recursive relationship. The
relation is between NodeA and NodeB, where NodeA whould be the parent
and NodeB the child.
If the recursive relatioship is lazy the list is loaded correctly when
the property is requested, but when child elements need to be loaded
eagerly the list never loads, even using eagerload option.

-------------------------------------------------------------------
Test Case:

from sqlalchemy import *
from sqlalchemy.ext.assignmapper import assign_mapper
from sqlalchemy.ext.sessioncontext import SessionContext
from sqlalchemy.ext.selectresults import SelectResults

ctx = SessionContext(create_session)
session = ctx.current
metadata = MetaData()

table = Table("node_table", metadata,
    Column('id', Integer, primary_key=True),
    Column('number', Unicode(10), nullable=False),
    Column('parent_id', Integer, ForeignKey('node_table.id'))
)

class NodeA(object): pass
class NodeB(object): pass

assign_mapper(ctx, NodeB, table)
# With lazy=True here the list IS loaded when needed
assign_mapper(ctx, NodeA, table, properties={'b_childs':
relation(NodeB, lazy=False)})

metadata.bind = create_engine('sqlite://', echo=True)
metadata.create_all()

table.insert().execute(number=1)
table.insert().execute(number=2)
table.insert().execute(number=3, parent_id=1)
table.insert().execute(number=4, parent_id=1)
table.insert().execute(number=5, parent_id=2)

a = SelectResults(session.query(NodeA)).filter(NodeA.c.id==1).list()
[0]
# If recursive relationship is lazy b child nodes are loaded, but if
relationship is not lazy they are never loaded
# even when using eagerload option
print a.b_childs

Does anyone knows what's the problem here ? I'm using sqlalchemy
version 0.3.9.
Regards !


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

Reply via email to