mirror of
https://github.com/fastapi/sqlmodel.git
synced 2025-08-15 10:11:34 +08:00
✨ Add new method sqlmodel_update()
to update models in place, including an update
parameter for extra data (#804)
This commit is contained in:

committed by
GitHub

parent
7fec884864
commit
fa12c5d87b
@ -80,8 +80,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)
|
||||
|
Reference in New Issue
Block a user