ฉันมีฐานข้อมูลนักเรียนใน SQLAlchemy พร้อมตารางต่อไปนี้
class Marks(Base):
__table_args__ = {'extend_existing': True}
__tablename__ = 'marks'
id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
mark = Column(Integer, nullable=False, unique=False)
subject_fk = Column(Integer, ForeignKey('subjects.id'))
subject = relationship('Subjects', foreign_keys=[locale_fk],uselist=False,
backref='marks', innerjoin=False, post_update=False)
class Subjects(Base):
__table_args__ = {'extend_existing': True}
__tablename__ = 'subjects'
id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
subject = Column(String(10, convert_unicode=True), nullable=False, unique=True)
class StudentIds(Base):
__table_args__ = {'extend_existing': True}
__tablename__ = 'student_ids'
id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
student_id = Column(String(50, convert_unicode=True), nullable=False,unique=False)
junctionid = relationship("Junction", cascade='save-update',
backref='student_ids', lazy='select', post_update=True)
mk=relationship("Marks",secondary=lambda:junction_table)
marks = association_proxy('mk', 'mark')
class Junction(Base):
__table_args__ = {'extend_existing': True}
__tablename__ = "junction_table"
student_id_fk = Column(Integer, ForeignKey('student_ids.id'), primary_key=True)
mark_fk = Column(Integer, ForeignKey('marks.id'), primary_key=True)
mark = relationship('Marks', cascade='save-update', backref='mark_id_mapper', innerjoin=True)
ฉันมีข้อมูลที่บรรจุอยู่ในตาราง Student Ids, Marks และ Subjects.. ตอนนี้ ฉันต้องเติมข้อมูลในตารางเชื่อมต่อด้วย student_id และ mark คีย์ต่างประเทศ (เครื่องหมายที่ได้รับในแต่ละ หัวเรื่องถูกแทรกลงในตารางเครื่องหมาย) ฉันจะทำสิ่งนี้ได้อย่างไร ฉันหมายความว่าฉันสามารถสร้างพร็อกซีการเชื่อมโยงภายในตารางรหัสนักเรียนที่แมปกับตารางมาร์กและเติมข้อมูลลงในตารางนั้นได้
ฉันอ่านเอกสารนี้แล้ว: http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/associationproxy.html และฉันเข้าใจว่าฉันต้องการพรอกซีนี้ระหว่าง Student_id และเครื่องหมาย.. เพื่อที่ฉันจะสามารถสืบค้น Student_id.mark เพื่อรับเครื่องหมายได้ แต่ฉันจะเอามันไปไว้ในตาราง Junction ได้อย่างไร?
ใครช่วยกรุณาแนะนำฉันหน่อยได้ไหม?