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

Allow objects in attributes for create/update routes (sqlalchemy) #172

Open
cycledriver opened this issue Oct 14, 2022 · 0 comments
Open

Comments

@cycledriver
Copy link

cycledriver commented Oct 14, 2022

This is something I've implemented for sqlalchemy at my day job. Wondering if it's useful to others...

For one-2-many and many-2-many relationships, it would be nice to allow the create and update routes to accept a partial object in the foreign key attribute. For example:

client.post("/heros", json={
    "name": Bob,
    "team": {"name": "Avengers"}
}

As is today, you need to do the following:

client.post("/heros", json={
    "name": Bob,
    "team_id": 42
}

I've created PR #171 with an initial implementation. Would appreciate feedback. I'm not 100% happy with the way that I've connected the read and table objects and would welcome ideas on that.

One other feature that would be nice would be to allow for sub-object creation. That could be enabled at the route level with some arg. I don't have a need for that right now, but would be good for a full solution.

I've only implemented this for SQLAlchemy as that's all I'm using right now. Would probably be applicable to other back-ends as well.

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

No branches or pull requests

1 participant