Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't update a foreign key value #176

Open
alprotasov opened this issue Jun 27, 2018 · 3 comments
Open

Can't update a foreign key value #176

alprotasov opened this issue Jun 27, 2018 · 3 comments
Labels

Comments

@alprotasov
Copy link

alprotasov commented Jun 27, 2018

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 alprotasov changed the title Can't update foreign key value Can't update a foreign key value Jun 27, 2018
@dkellner
Copy link
Collaborator

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.

@alprotasov
Copy link
Author

alprotasov commented Jun 28, 2018

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())

@dkellner
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants