Florian Boesch wrote:
Table('children', engine,
Column('children_id', Integer, Sequence('children_seq'),
    primary_key=True),
Column('tag_node_id', Integer, ForeignKey('tag_node.id'),
    nullable=False),
Column('node_id', Integer, ForeignKey('node.id'), nullable=False),
Column('ordering', Integer, nullable=False),
)

I'd prefer to have a list of parent nodes; one of the properties of these trees is that each node has one parent only (except root, which has none):

CREATE TABLE parents (
    node_id   INTEGER NOT NULL REFERENCES node(id),
        parent_id INTEGER NOT NULL REFERENCES node(id),
        ordering  INTEGER NOT NULL,
        
        PRIMARY KEY (node_id, parent_id),
        UNIQUE (node_id, ordering) -- probably screwed the syntax here
);

This way, you can select all of a node's children (by checking if it's referenced in the parent_id column) or select all parents (by getting the list of parent's for a node).

Thank you once again Mike, for providing that article; I still can't wrap my brain around it properly, but this model seems quite nice.

--
Luís Bruno
"You see, it's our tears, Stan, that give God his great power."
        -- Chef, Southpark


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to