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

[sqlalchemy] allow create/update with object for one/many 2 many #171

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cycledriver
Copy link

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

@vercel
Copy link

vercel bot commented Oct 14, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
fastapi-crudrouter ❌ Failed (Inspect) Oct 14, 2022 at 0:33AM (UTC)

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
@vercel
Copy link

vercel bot commented Jan 28, 2023

Someone is attempting to deploy a commit to a Personal Account owned by @awtkns on Vercel.

@awtkns first needs to authorize it.

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

Successfully merging this pull request may close these issues.

None yet

2 participants