Hi!

I wanted to know how to create a many-to-many relationship where parents
and children belong to the same table. My code looks like this (the
actual names of the tables have been replaced to protect the culprit):

nodes = Table('nodes', metadata,

    Column('ID', Integer, primary_key=True),

    Column('Name', Unicode(100)),

    )

nodesparents = Table('nodesparents', metadata,

    Column('NodeID', Integer, ForeignKey('nodes.ID')),

    Column('ParentNodeID', Integer, ForeignKey('nodes.ID'))

    )



Besides the horrible naming convention, that should be OK. Now to the
mapper:

assign_mapper(session.context, Node, nodes,

        properties = {

            'Parents': relation(Node, primaryjoin = nodesparents.c.ParentNodeID 
== nodes.c.ID),

            'Children': relation(Node, primaryjoin = nodesparents.c.NodeID == 
nodes.c.ID)

            }

    )



Well, that's what I've come to after readin sqlalchemy's wiki, in the
usage recipes section. I've tried creating the relations using the
'secondary' parameter, backrefs, etc. Nothing works. Am I missing
something? I just want to create a graph like structure where each node
can have more than one parent and more than one child, is that possible
using SQLAlchemy? (I suppose it is, but for the life of me can't find
the way).

Thanks in advance,
David

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

Reply via email to