Hi, Allen! You can use something like this (yeah, I know that it isn't declarative in any way):
class Node(Base): __tablename__ = 'node' id = Column(Integer, primary_key=True) parent_id = Column(ForeignKey('node.id')) parent = relation("Node", remote_side=[id]) mp_path = Column(sqlamp.PathField()) mp_depth = Column(sqlamp.DepthField()) mp_tree_id = Column(sqlamp.TreeIdField()) Node.mp = sqlamp.MPManager( Node.__table__, pk_field='id', parent_id_field='parent_id', path_field_name='mp_path', depth_field_name='mp_depth', tree_id_field_name='mp_tree_id' ) Node.__mapper__.extension.append(Node.mp.mapper_extension) Note that you need to define mp_* colums. You doesn't need it if you create MPManager *before* creating mapper. On the other hand you can use this hack (but I wouldn't recomend it): class Node(Base): __tablename__ = 'node' id = Column(Integer, primary_key=True) parent_id = Column(ForeignKey('node.id')) parent = relation("Node", remote_side=[id]) Node.mp = sqlamp.MPManager( Node.__table__, pk_field='id', parent_id_field='parent_id' ) Node.__mapper__.extension.append(Node.mp.mapper_extension) Node.__mapper__._configure_properties() allen.fowler: > Werner, > > On Aug 7, 12:36 pm, werner <wbru...@free.fr> wrote: > > Allen, > > > > allen.fowler wrote: > > > > > On Aug 6, 6:54 pm, AF <allen.fow...@yahoo.com> wrote: > > > > >> Hello all, > > > > >> Has anyone here used the "sqlamp: Materialized Path for SQLAlchemy" > > >> library? > > > > >> I am wondering: > > > > >> 1) Does it seem to work well? > > > > >> 2) Did you use it with Declarative Base, and if so, how did you > > >> configure it? > > > > > Anybody? > > > > > Specifically, I am wondering about how adapt the sample code at: > > > > >http://sqlamp.angri.ru/#quickstart > > > > > ... so that it works with declarative base. > > > > I haven't used this library and I am no SA expert so take the following > > with a grain (or two) of salt. > > > > I would translate this: > > > > class Node(object): > > mp = sqlamp.MPManager( > > node_table, node_table.c.id, node_table.c.parent_id > > ) > > > > To: > > class Node(Base): > > __table__ = sa.Table(u'node', metadata, > > sa.Column(u'id', sa.Integer(), sa.Sequence('gen_sample_id'), > > primary_key=True, nullable=False), > > sa.Column(u'parent_id', sa.Integer(), sa.ForeignKey(u'node.id')), > > ... > > ) > > > > mp = sqlamp.MPManager( > > __table__, __table__.c.id, __table__.c.parent_id) > > > > Werner > > Thank you... > > Though, that does not look at all like typical Declarative Base code > I've seen / been using. Why the explicit assignment to __table__? > > Further, where does the "extension=[Node.mp.mapper_extension]" binding > happen? > > Thank you again, > AF --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---