Right now i'm considering changing to 0.4 . Assign 2 different classes to the same table was the first thing that i thought, because A and B are "exactly" the same, the only difference is that only one kind of A ( the B class :) ) can have a parent A but no children. The A class can have many B as children.
Thank you very much Michael !! Best Regards, Jeronimo On Aug 15, 5:47 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > hi Jeronimo - > > eager loading of self-referential relationships is not supported in > version 0.3. this is a new feature as of version 0.4, using the > "join_depth" option to indicate how many levels deep youd like to > eagerly-join. in any case, even when eager loading is specified, the > load should "fall back" to a lazyload if eager loading could not occur. > > However, assigning two different classes to the same table, without > any inheritance identifiers, is also something that has never been > done before, so additional testing may be needed ensure that works. > But I would ask if its really necessary to map two different classes > like that ? how do they differ ? > > Trying your test with 0.4, and using the "join_depth" option as > described athttp://www.sqlalchemy.org/docs/04/ > mappers.html#advdatamapping_relation_selfreferential_eagerloading , > is worth a try. If you can use just a single class, that will > definitely work. For a description of how self-referential loading > normally works with 0.4 and (also pretty much with 0.3 as well), see > http://www.sqlalchemy.org/docs/04/ > mappers.html#advdatamapping_relation_selfreferential . > > hope this helps, > > - mike > > On Aug 15, 2007, at 12:54 PM, Jeronimo wrote: > > > > > 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 [email protected] 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 -~----------~----~----~----~------~----~------~--~---
