following the example in the mapper configuration documentation i've come up with:
mapper(Contact, contacts,, properties={ '_created_by': contacts.c.created_by, '_updated_by': contacts.c.updated_by, 'created_by': relation(Contact, primaryjoin=contacts.c.created_by==contacts.c.id, remote_side=[contacts.c.id]), 'updated_by': relation(Contact, primaryjoin=contacts.c.updated_by==contacts.c.id, backref=backref('updated_by_me', primaryjoin=contacts.c.updated_by==contacts.c.id, remote_side=[contacts.c.id])), }) Both of these configurations set their respective _ properties rather than update the actual database row. Thank you very much for your help. On May 28, 6:16 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > this is a many-to-one self-referential relationship. the > "remote_side" attribute is needed on both relations() to establish > this, and the uselist=False is not needed (its hiding the actual error > here). See the docs on "self-referential mappings". > > On May 28, 2008, at 6:11 PM, kremlan wrote: > > > > > My goal is to have a one-to-one relation defined using the same name > > as the foreign key column underneath. I have 'contacts' table with > > 'created_by' and 'updated_by' columns which are FKs to contacts.id. > > > contacts = Table('contacts', meta, > > Column('id', Integer, primary_key=True), > > Column('first_name', String(25)), > > Column('middle_name', String(25)), > > Column('last_name', String(25)), > > # etc... > > Column('created_at', DateTime), > > Column('updated_at', DateTime), > > Column('created_by', Integer), > > Column('updated_by', Integer), > > ForeignKeyConstraint(['created_by'], ['contacts.id']), > > ForeignKeyConstraint(['updated_by'], ['contacts.id']) > > ) > > > mapper(Contact, contacts, properties={ > > '_created_by': contacts.c.created_by, > > '_updated_by': contacts.c.updated_by, > > 'created_by': relation(Contact, > > primaryjoin=contacts.c.created_by==contacts.c.id, uselist=False), > > 'updated_by': relation(Contact, > > primaryjoin=contacts.c.updated_by==contacts.c.id, uselist=False), > > }) > > > The primaryjoin is necessary due to the multiple FKs back to contacts. > > > This follows the pattern suggested here: > >http://groups.google.pl/group/sqlalchemy/browse_thread/thread/e20bb32... > > > No errors occur but the 'created_by' column in the table is not > > actually updated upon flush/commit. Instead the _created_by attribute > > is updated. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---