I am working on a simple rest api using flask-sqlalchemy and flask-marshmallow.
For the PUT method I have below data:-
{ "childlist" : [
{
"childfield1" : "Value1", --> field of related table
"childfield2" : "Value2" --> field of related table
}
],
"parentprimarykey1": "VAL1", --> this is the foreign key for child table
"parentfield2" : "VAL2",
"parentfield3" : "VAL3"
}
When I pass this json to a PUT method and run the schema.load(request_data). SQLAlchemy is runs a Update SQL for the child table trying to update the foreign key with NULL.
Why an update statement is fired to update the foreign key? What is the best way to implement the update for the REST API?
my schema for the model looks like this Parent
class Parent(db.Model):
all fields
childlist=db.relationship('Parent', backref=db.backref('parent', cascade='delete, all', lazy='joined'))
class ParentSchema(ma.ModelScema):
childlist=ma.Nested(child, many=True)
class Meta:
model=Parent
sqla_session=db.session
the error is raised by this line in the view:- parent_schema.load(request_data)