I was wondering if it is possible to set up joined table inheritance
so that a subclass inherits from more than one base table. To extend
the example given in the documentation, we would have a base class
'Employee' and a base class 'Citizen' such that an 'Engineer' would
inherit from both Employee and Citizen classes and have independent
'citizen_id' and 'employee_id'. One could imagine other classes that
only inherit from either employee or citizen.

employees = Table('employees', metadata,
   Column('employee_id', Integer, primary_key=True),
   Column('employee_type', String(30), nullable=False)
)

citizens = Table('citizens', metadata,
   Column('citizen_id', Integer, primary_key=True),
   Column('citizen_type', String(30), nullable=False)
)

An engineer who is both an employee and a citizen would have am
employee_id and a citizen_id:

engineers = Table('engineers', metadata,
   Column('id', Integer, primary_key=True)
   Column('employee_id', Integer,
ForeignKey('employees.employee_id')),
   Column('citizen_id', Integer, ForeignKey('citizens.citizen_id')),
   Column('engineer_info', String(50)),
)

And the classes would look like

class Employee(object):
    pass

class Citizen(object):
    pass

class Engineer(Employe, Citizen):
    pass

And the mappers for the base classes would be something like:
mapper(Employee, employees, polymorphic_on=employees.c.employee_type,
polymorphic_identity='employee')
mapper(Citizen, citizens, polymorphic_on=citizens.c.citizen_type,
polymorphic_identity='citizen')

While the mapper for the engineer has argument 'inherits_multi' and
looks like:
mapper(Engineer, engineers, inherits_multi=[Employee, Citizen],
polymorphic_identity='engineer')

I realize that the mapper does not have an 'inherits_muti' argument
and that multiple inheritance is not supported. I also saw this thread
from back in 2006:
http://www.mail-archive.com/[EMAIL PROTECTED]/msg03303.html

For my application, this pattern is important (the above example is
only an example of the pattern, I'm not really modeling employees and
citizens) and I was wondering if anyone had any suggestions as to how
to go about implementing this functionality, which I'm planning on
doing.

Also, thanks to the folks on this list who have responded to my
previous questions. I'm hoping that someone else would find this
functionality useful and I can share my (yet to be had) solution with
the community.

Sam




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to