python - update duplicates data in relationship flask sqlalchemy -
i have flask-restless api add , retrieve data database. of fields need localised clients there auxiliary table language , string each field.
class myclass(base): __tablename__ = 'myclass' id = column(integer, primary_key = true) translated_field = relationship('translatedfield')
and translation table:
class translatedfield(base): __tablename__ = 'translated_field' id = column(integer, primary_key = true) myclassid = column(integer, foreignkey('myclass.id')) language = column(string(2)) value = column(text)
inserts through json work fine {...,"translated_field":[{"language":"en", "value": "some value"}],...}
but when same put
request, sets myclassid null in existing row in translated_field
table , inserts new row modified data rather updating existing one.
obviously not ok because fills database garbage. question is: can modify existing rows or have "clean" db manually in pre or post processor?
solved it. turns out wasn't passing values primary key (autoincrement id) of related objects didn't know update.
request fragment should ...,"translated_field":[{"id":3 "language":"en", "value": "some value"}],...}
Comments
Post a Comment