from sqlalchemy import *

pg_engine=create_engine('sqlite://', echo=True)
people = Table("people", pg_engine,
   Column('key', String, primary_key=True),
   Column('firstname', String),
   Column('lastname', String),
).create()

bornpeople = Table("bornpeople", pg_engine,
   Column('person', String, ForeignKey("people.key"),  
primary_key=True, ),
   Column('birthdate', DateTime, nullable=False),
).create()

prefs = Table("prefs", pg_engine,
   Column('person', String, primary_key=True),
   Column('email', String),
).create()

class Prefs(object):
   pass

class Person(object):
   pass

class BornPerson(Person):
   pass

Prefs.mapper = mapper(Prefs, prefs)

Person.mapper = mapper(Person, people, order_by=people.c.lastname,
         properties = {
         'Prefs' : relation(Prefs.mapper, uselist=False,
           primaryjoin=prefs.c.person==people.c.key,
           foreignkey=prefs.c.person),
       },
     )

BornPerson.mapper = mapper(BornPerson, bornpeople,
         inherits=Person.mapper,
     )

p = Person()
p.key = 'default'
pr = Prefs()
pr.email = 'lla@foo.com'
p.Prefs = pr
objectstore.flush()

objectstore.clear()
p = Person.mapper.get('default')
print p.key
print p.Prefs.person