Hi guys,

I’m to build an adjacency list in SA and have looked at the
basic_tree.py example provided, however, I need to order the children.
Now I don’t really want to use nested sets and I know linked lists can
be implemented in SA quite easily.

So naturally I tried something like

trees = Table('treenodes', metadata,
    Column('id', Integer, Sequence('treenode_id_seq', optional=True),
           primary_key=True),
    Column('parent_id', Integer, ForeignKey('treenodes.id'),
nullable=True),
    Column('name', String(50), nullable=False),
    Column('next_id', Integer, ForeignKey('treenodes.id'),
unique=True, nullable=True)
    )

mapper(TreeNode, trees, properties={
        'children': relation(TreeNode, cascade="all",
                             backref=backref("parent", remote_side=
[trees.c.id]),
 
collection_class=attribute_mapped_collection('name'),
                             lazy=False, join_depth=3),
        'next' :    relation(TreeNode, uselist=False,
 
remote_side=trees.c.id,
                             backref=backref('previous',
uselist=False))}
       )

Of course this does not work as it's a many to many relation (and so
needs another table). I would really prefer if I could get away with
just using one table though. Is there a way to do it?

Thanks.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to