2 messages in com.googlegroups.sqlalchemy[sqlalchemy] Problem Mapping table/re...
FromSent OnAttachments
Nathan Harmston24 Aug 2007 16:40 
Michael Bayer24 Aug 2007 17:15 
Subject:[sqlalchemy] Problem Mapping table/relationship to a dictionary.
From:Nathan Harmston (ratc@googlemail.com)
Date:08/24/2007 04:40:53 PM
List:com.googlegroups.sqlalchemy

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.

Nathan