-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sqlalchemy] allow create/update with object for one/many 2 many
For one-2-many and many-2-many relationships, 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"} } Assuming there is already a team called Avengers, Bob will be created, the Team with name "Avengers" will be looked up and used to populate Bob's team_id foreign key attribute. The only setup required is for the input model for the foreign object to specify the Table class that can be used to lookup the object. For example: class Team(Base): """Team DTO.""" __tablename__ = "teams" id = Column(Integer, primary_key=True, index=True) name = Column(String, unique=True) class TeamUpdate(Model): name: str class Meta: orm_model = Team
- Loading branch information
1 parent
66fd32f
commit 18a9aaa
Showing
2 changed files
with
362 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.