Skip to content

Commit

Permalink
dynamically get pk column
Browse files Browse the repository at this point in the history
  • Loading branch information
Micheal Gendy committed Feb 2, 2022
1 parent cea7515 commit 592ebba
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions orm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ async def bulk_update(
]
expr = (
self.table.update()
.where(self.table.c.id == sqlalchemy.bindparam(self.pkname))
.where(
getattr(self.table.c, self.pkname) == sqlalchemy.bindparam(self.pkname)
)
.values(
{
field: sqlalchemy.bindparam(field)
Expand All @@ -498,7 +500,7 @@ async def bulk_update(
}
)
)
pk_list = [{self.pkname: obj.pk} for obj in objs]
pk_list = [{self.pkname: getattr(obj, self.pkname)} for obj in objs]
joined_list = [{**pk, **value} for pk, value in zip(pk_list, new_objs)]
await self.database.execute_many(str(expr), joined_list)

Expand Down

0 comments on commit 592ebba

Please sign in to comment.