eve-sqlalchemy icon indicating copy to clipboard operation
eve-sqlalchemy copied to clipboard

Can't update a foreign key value

Open alprotasov opened this issue 7 years ago • 3 comments

Hello!

I have a foreign key field: user = Column(Integer(), ForeignKey('clean_controller.id'))

When I try to make a PATCH/PUT request with the request body {"user": 11}

I get HTTP/1.0 422 UNPROCESSABLE ENTITY There is a clean_controller table and there is a row with id 11 in it. class CleanPoint(CommonColumns): tablename = 'clean_point' id = Column(Integer(), primary_key=True, autoincrement=True) ....

What is the correct way to update it?

alprotasov avatar Jun 27 '18 17:06 alprotasov

The response body should contain more information on why the validation failed, can you provide that one, too?

One thing that could be the problem: you're referring to clean_controller but your example only contains clean_point.

dkellner avatar Jun 28 '18 01:06 dkellner

Sorry. Copy-pasted incorrect class. class CleanController(CommonColumns): tablename = 'clean_controller' id = Column(Integer(), primary_key=True, autoincrement=True) name = Column(VARCHAR(30))

And the error is {"_issues": {"user": "unknown field"}, "_status": "ERR"}

After I removed FK from the field it works fine. I mean user = Column(Integer())

alprotasov avatar Jun 28 '18 07:06 alprotasov

You'll need to add a relationship too, e.g. as in https://github.com/pyeve/eve-sqlalchemy/blob/master/examples/many_to_one/many_to_one/domain.py . At the moment plain ForeignKeys are not exposed by the API.

dkellner avatar Jun 30 '18 09:06 dkellner