4 Sep 02:46
Multiple Inheritance
From: Sam Magister <smagister <at> gmail.com>
Subject: Multiple Inheritance
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-09-04 00:47:35 GMT
Subject: Multiple Inheritance
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-09-04 00:47:35 GMT
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)),
)
(Continue reading)
RSS Feed