class Employee(Base):
__tablename__ = 'employee'
id = Column(Integer, primary_key=True)
name = Column(String(50))
type = Column(String(50))
__mapper_args__ = {
'polymorphic_identity':'employee',
'polymorphic_on':type
}
class Engineer(Employee):
__tablename__ = 'engineer'
id = Column(Integer, ForeignKey('employee.id'), primary_key=True)
engineer_name = Column(String(30))
__mapper_args__ = {
'polymorphic_identity':'engineer',
}
class Manager(Employee):
__tablename__ = 'manager'
id = Column(Integer, ForeignKey('employee.id'), primary_key=True)
manager_name = Column(String(30))
__mapper_args__ = {
'polymorphic_identity':'manager',
}
如上有 员工、工程师、管理者 3 个表。
e = Employee.query.filter(xxx=xxx).first()
我想给 e 加上 Manager 和 Engineer 的角色应该如何表达?
就是一个员工可以有多种角色。
1
qwer1234asdf 2016-11-23 17:24:27 +08:00
表本身就建的有问题
|
2
weyou 2016-11-23 18:06:54 +08:00
就不该拆表,加一个 role 字段,然后关联到 role 表
|
3
ryd994 2016-11-24 04:17:35 +08:00 via Android
学好范式………
|
4
tanywei OP 看官方文档想到的而已,谢谢大家。
|