У меня есть студенческая база данных в 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 and Subjects. Теперь мне нужно заполнить соединительную таблицу внешними ключами student_id и mark (оценки, полученные в каждом предметы вставляются в таблицу отметок). Как мне это сделать, я имею в виду, что я могу создать прокси-ассоциацию внутри таблицы идентификаторов учащихся, которая сопоставляется с таблицей отметок, и заполнить ее там?
Я просмотрел эту документацию: http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/associationproxy.html и я как бы понимаю, что мне нужен этот прокси между student_id и отметками... чтобы я мог запросить student_id.mark для получения отметок. Но как мне получить это в моей таблице Junction?
Может кто-нибудь, пожалуйста, направьте меня?