Add new method sqlmodel_update() to update models in place, including an update parameter for extra data (#804)

This commit is contained in:
Sebastián Ramírez
2024-02-17 14:49:39 +01:00
committed by GitHub
parent 7fec884864
commit fa12c5d87b
15 changed files with 1871 additions and 26 deletions

View File

@ -78,8 +78,7 @@ def update_hero(hero_id: int, hero: HeroUpdate):
if not db_hero:
raise HTTPException(status_code=404, detail="Hero not found")
hero_data = hero.model_dump(exclude_unset=True)
for key, value in hero_data.items():
setattr(db_hero, key, value)
db_hero.sqlmodel_update(hero_data)
session.add(db_hero)
session.commit()
session.refresh(db_hero)