On Jan 11, 2008 7:57 PM, Jonathan LaCour <[EMAIL PROTECTED]> wrote: > > Jonathan LaCour wrote: > > >> I am attempting to model a doubly-linked list, as follows: > > > > ... seems to do the trick. I had tried using backref's earlier, > > but it was failing because I was specifying a "remote_side" > > keyword argument to the backref(), which was making it blow up > > with cycle detection exceptions for some reason. > > Oops, spoke too soon! Here is a test case which shows something > quite odd. I create some elements, link them together, and then > walk the relations forward and backward, printing out the results. > All seems fine. Then, I update the order of the linked list, and > print them out forward, and they work okay, but when I print things > out in reverse order, its all screwy. > > Any ideas?
I believe you need either the only next_task_id or the only previous_task_id, but not both, since one can be calculated from another. Something like the following: task_table = Table('task', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode), Column('next_task_id', Integer, unique=True, ForeignKey('task.id')), ) Session.mapper(Task, task_table, properties={ 'next_task' : relation( Task, uselist=False, remote_side=task_table.c.id, backref=backref('previous_task', uselist=False), ), }) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---