很抱歉标题中的大字,但我正在努力解决这个问题
在我的教育机构数据库的时间表部分中,有课程(班级)和测试表。两者都以学生、教师、房间甚至更多的形式在给定的时间点索取资源。因此,我的关联表从TestExam或课程连接到学生、教师或房间(…)。我想被文件和各种各样的文章发送到很多不同的方向,但是没有一个更聪明。
This关于SO的文章似乎让我接近了,但还不是很到位。 The documentation on polymorphic似乎表明这是不可能的。你知道吗
顺便说一句,这些类是从数据库中的现有视图中反映出来的,因为在数据层中有更多关于更改跟踪的功能。
Claim
表(my association table)具有与课程或测试AM相关的claimer_id
和claimer
类型(=鉴别器),以及与教师、学生、房间相关的claimtype
(=鉴别器)和claim
。。
为了简单起见,我在这里只提供多态性的一个实例。
有人能给我举个例子来说明这一点吗?还是我完全走错了方向?
class Lesson(Base):
__tablename__ = 'tx_lesson'
pk = Column(Integer, FetchedValue())
lesson_id = Column(Integer, FetchedValue(), primary_key=True)
Lesson.claims = relationship('<claim?>',
primaryjoin="and_(Lesson.lesson_id == <claim?>.claimer_id,
<claim?>.claimertype == 'Lesson')",
back_populates='lessons', viewonly=True)
class Claim(Base):
__tablename__ = 'tx_claim'
pk = Column(Integer, FetchedValue())
claim_id = Column(Integer, FetchedValue(), primary_key=True)
claimer_id = Column(Integer, ForeignKey('<TestExam Or Lesson' _id))
claim = Column(Integer, ForeignKey('<Teacher, Student or Room' _id))
class Student(Base):
__tablename__ = 'tx_student'
pk = Column(Integer, FetchedValue())
student_id = Column(Integer, FetchedValue(), primary_key=True)
__mapper_args__ = {'<Some Polymorphic black magic here>'}
class Teacher(Base):
# similar columns ...
pass
目前没有回答
相关问题 更多 >
编程相关推荐