I'm using the "joined table inheritance" model. I have three levels of
inheritance.
class has_polymorphic_id(object):
@declared_attr.cascading
def record_id(cls):
if has_inherited_table(cls):
return Column(ForeignKey('employee.record_id'),
primary_key=True)
else:
return Column(Integer, primary_key=True)
class Employee(has_polymorphic_id, Base):
__tablename__ = 'employee'
name = Column(String(50))
type = Column(String(50))
__mapper_args__ = {
'polymorphic_identity':'employee',
'polymorphic_on':type
}
class Engineer(Employee):
__tablename__ = 'engineer'
....
class Programmer(Engineer):
__tablename__ = 'programmer'
....
This only works for the second level, namely `Enginner` can inherits the
foreignkey/primarykey from `Employee`'s mixin, but the next level, the
`Programmer`, python gives me an error:
`sqlalchemy.exc.NoForeignKeysError: Can't find any foreign key
relationships between 'engineer' and 'programmer'.`
Is this designed this way? And if I manually set the foreignkey, should the
third level reference to the base level or to its immediate parent level's
primarykey?
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/02ce8134-2946-4d1b-b6d3-e47ad7944e0en%40googlegroups.com.