i think the mapper should be used only for its main purpose, which is
persistence.  this would indicate that your mapper is just the most
basic mapper, on Node with relationships to other Nodes via the edges
table (probably want to make an Edge object too).   anything beyond
that, you should use the Query object...but actually with this example
i realized you dont even have to...

class Node(object):
    def __init__(self, id):
        self.nodeid = id
    def add_neighbor(self, othernode):
        Edge(self, othernode)
    def higher_neighbors(self):
        return [x.upper_node for x in self.lower_edges]
    def lower_neighbors(self):
        return [x.lower_node for x in self.upper_edges]

class Edge(object):
    def __init__(self, n1, n2):
        if n1.nodeid < n2.nodeid:
            self.lower_node = n1
            self.upper_node = n2
        else:
            self.lower_node = n2
            self.upper_node = n1

mapper(Node, nodes)
mapper(Edge, edges, properties={
    'lower_node':relation(Node,
primaryjoin=edges.c.lower==nodes.c.nodeid, backref='lower_edges'),
    'higher_node':relation(Node,
primaryjoin=edges.c.higher==nodes.c.nodeid, backref='upper_edges')
    }
)

n1 = Node(1)
n2 = Node(2)
n3 = Node(3)
n2.add_neighbor(n3)

[session.save(x) for x in [n1, n2, n3]]
session.flush()

im beginning to regret having "viewonly" and "non_primary" as options,
since i cant think of anything they do that cant be better accomplished
just by using Query.select(), or manual queries in conjunction with
query.instances().  I think im going to try to express this in the
documentation...


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

Reply via email to