On Sep 27, 2006, at 4:15 PM, Matias Hermanrud Fjeld wrote: > Here is (part of) the table SA is working with. > > Table('categories', > BoundMetaData(), > Column('categories_id',<sqlalchemy.databases.mysql.MSInteger object > at > 0x4060a5ec>,key='categories_id',primary_key=True,nullable=False,hidden > =False,default=None,onupdate=None), > Column('parent_id',<sqlalchemy.types.Integer object at > 0x4060742c>,ForeignKey > ('categories.categories_id'),key='parent_id',primary_key=False,nullabl > e=True,hidden=False,default=None,onupdate=None), > [snip uninteresting columns] > schema=None) > > The mapper: > > sa.mapper( > Category, categories, properties=dict( > children=sa.relation( > Category, backref=sa.backref('parent', uselist=False) > ), > [snip] > ) > ) > > Is there anything special I have to do to tell SA that the > dependency should only go one way? >
yeah, becuase this mapper is self-referring, the "parent" backref needs a clue that the relationship is in the opposite direction, like this: sa.mapper( Category, categories, properties=dict( children=sa.relation( Category, backref=sa.backref('parent', uselist=False, foreignkey=categories.c.categories_id) ), [snip] ) ) see the example in http://www.sqlalchemy.org/docs/ adv_datamapping.myt#advdatamapping_recursive for this, as well as the examples in the /examples directory of the distribution. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users