On Aug 24, 2007, at 7:41 PM, Nathan Harmston wrote:
> > Hi, > > I m trying to write a way of storing a 2 level dictionary in a > database. > > class Foo(object): > def __init__(self): > self.a = {} > def __iadd__(self, i): > if i not in self.a: > self.a[i] = {} > return self > def keys(self): > for i in self.a.keys(): > yield i > def __getitem__(self, k): > return self.a[k] > def save(self): > # saves the object in the database > > f = Foo() > f += Node1 > f[Node1][Node2] = edge > > THe idea is that its a self-referential join (node1 -> node2 ) with > association object (edge), ie. node1 has many edges. one edge has has > node1 and 1 node 2. > > IS there a pattern in sqlalchemy for doing this sort of thing, I > noticed in the new version of SQLalchemy you can map to sets, but I m > a little clueless where to start. > > Any help muchly appreciated. the example examples/adjacencytree/basic_tree.py illustrates a self- referential Node class which contains a map of child nodes. For a pattern dealing with "edges" in the middle, theres an example eaxmples/graph/graph.py . --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---