Answer the question
In order to leave comments, you need to log in
How to update data in an associative table?
There are the following models in alchemy:
RecordAndTask = Table('record_and_task', Base.metadata,
Column('record_id', String, ForeignKey('record.id'), primary_key=True),
Column('task_id', String, ForeignKey('task.id'), primary_key=True))
RecordAndWidget = Table('record_and_widget', Base.metadata,
Column('record_id', String, ForeignKey('record.id'), primary_key=True),
Column('widget_id', String, ForeignKey('widget.id'), primary_key=True))
class Record(Base):
__tablename__ = 'record'
id = Column(String, primary_key=True)
tasks = relationship('Task', secondary=RecordAndTask, backref=backref('records', lazy='dynamic'), lazy='dynamic')
widgets = relationship('Widget', secondary=RecordAndWidget, backref=backref('records', lazy='dynamic'), lazy='dynamic')
class Task(Base):
__tablename__ = 'task'
id = Column(String, primary_key=True)
status = Column(String)
widget_id = Column(String, ForeignKey('widget.id'))
class Widget(Base):
__tablename__ = 'widget'
id = Column(String, primary_key=True)
tasks = relationship('Task', backref='widget', lazy='dynamic')
id='record_1'
id='record_2'
id='record_3'
id='task_1', status='done', widget_id='widget_1'
id='task_2', status='failed', widget_id='widget_3'
id='task_3', status='done', widget_id='widget_2'
id='widget_1'
id='widget_2'
id='widget_3'
record_id='record_1', task_id='task_1'
record_id='record_1', task_id='task_2'
record_id='record_2', task_id='task_3'
record_id='record_1', widget_id='widget_1'
record_id='record_1', widget_id='widget_3'
record_id='record_2', widget_id='widget_2'
id='task_1', status='done', widget_id='widget_1'
id='task_2', status='done', widget_id='widget_2' <- Изменился статус и id виджета
id='task_3', status='done', widget_id='widget_2'
record_id='record_1', widget_id='widget_1'
record_id='record_1', widget_id='widget_2' <- Должен измениться id и тут
record_id='record_2', widget_id='widget_2'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question