Thank you Michael, that works. All the best, Boris On Aug 16, 6:52 am, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Aug 16, 2007, at 12:23 AM, Boris Duek wrote: > > > > > > > Hi, > > > I am using sqlalchemy like this: > > > class Entry: pass > > table1 = sqa.Table('table1', meta, autoload=True) # this table has > > primary key 'id' > > table2 = sqa.Table('table2', meta, sqa.Column('table1_id', > > sqa.Integer, sqa.ForeignKey('table1.id'), autoload=True) > > table1 = table1.join(table2) # gets joined on the ForeignKey, a.k.a. > > table2.table1_id == table1.id > > sqa_orm.mapper(Entry, table1) > > session = sqa_orm.create_session() > > entry = Entry() > > entry.a = 1 > > ... # working with entry, setting values for all columns except id and > > table1_id > > session.save(entry) > > session.flush() > > > But now, the entry in table2 gets stored, but with NULL value in > > table1_id column. I would expect sqlalchemy to be the same smart as it > > is already with the join, and set table2.table1_id to the > > corresponding table1.id, because it knows about the foreign key. > > if you were using joined table inheritance with two mappers, it would > figure this out. but when mapping to just an arbitrary selectable, > it doesnt make any assumptions. in this particular case, you have to > give it an explicit hint that the two columns are the same: > > j = table1.join(table2) > mapper(Entry, j, properties={ > 'id':[table1.c.id, table2.c.table1_id] > > }) > > described at > > http://www.sqlalchemy.org/docs/04/ > mappers.html#advdatamapping_mapper_joins
--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---