On 5/29/06, Jamie Wilkinson <[EMAIL PROTECTED]> wrote:
So, I want to map an instance of Person onto both tables, so that part of
the information is stored in 'account', and some in 'person'. Obviously there
will be cases where rows in 'account' don't map to rows in 'person', so we
want the 'person.id' primary key to be the id for the mapper; but how to I
tell the mapper that the fields should map to different tables? My naive
attempt was this:
mapper(Person, join(account, person), properties = {
'id' : person.c.id,
'handle': person.c.handle,
'firstname': person.c.firstname,
'lastname': person.c.lastname,
'email_address': account.c.email_address,
'password': account.c.password,
})
but with echo=True in the engine, I'm seeing that the account primary key is
not being set in the foreign key column of person, and so when one tries to
retrieve the object from the session, it returns None.
Obviously I'm doing somethign wrong, because I'd expect SA to just handle
this case easily, (though it's never mentioned in the docs ;-), it seems
like an obvious thing to want to do.
Any ideas? Thanks in advance.
Have you looked at
http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_joins
yet? From those docs, it looks like you should be able to simply do
"mapper(Person, join(account, person))" and have it work as you
expect, with a two-column primary key on the Person objects composed
of the primary keys of each table (account and person). In other
words, do exactly what you were trying to do, but without the
"properties = ..." part.
I haven't actually tried this yet, so if you've already read those
docs and it's not working, then I don't know how to help you. But it
sure sounds from the documentation like what you're trying to do ought
to work.
--
Robin Munn
[EMAIL PROTECTED]
GPG key 0xD6497014