bun
bun copied to clipboard
`bun.UpdateQuery`'s `.Set` method causes any other model fields to be ignored
Updates to a model's fields appear to be ignored whenever .Set
is used on the query even when I add .Column
.
I often update a table through the model struct (account.UpdatedAt = time.Now()
), but also set some fields using a query like (q.Set("update_count = update_count + 1")
). Only the fields set with .Set
get updated. Is this by design? I remember being able to do this with go-pg
.
Example:
account.UpdatedAt = time.Now()
_, err := db.NewUpdate().Model(&account).WherePK().
Column("updated_at","update_count").Set("update_count = update_count + 1").
OmitZero().Returning("*").Exec(ctx)
generates the query:
UPDATE account SET update_count = update_count + 1 ...
instead of
UPDATE account SET updated_at = '2023-07-08T08:51:27.217Z' , update_count = update_count + 1 ...
Based on this and this it looks like .Set
and updating model struct fields are mutually exclusive - we return early as soon as len(q.set) > 0
. Any chance of combining the two update sources?
#647