Skip to content

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

Open
@cycledriver

Description

@cycledriver

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions