Equivalent of Update on Model on non primary key #1423
-
I have a PG table defined as CREATE TABLE pt ( ptModel.Update() works beautifully for partial update of 'days' using boil.WhiteList('days') field when WHERE clause is okay to be based on primary key values..
A) How can (if possible) equivalent be accomplished using non primary keys via alternate syntax.. (unique key -- 'uuid' in this case)? I understand there is UpdateAll, but in that case we need to build the list name, value pairs in the map to pass to the request.. =
Appreciate your response. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You would likely have to craft this query yourself: If you only need to update and don't necessarily care about the returned objects: err := models.Users(
qm.Where("uuid = ?", pt.UUID), qm.Where("c_id = ?", pt.CID),
).UpdateAll(ctx, exec, models.M{"days": pt.Days}) If you want to return the values: q := models.Users(
qm.Where("uuid = ?", pt.UUID), qm.Where("c_id = ?", pt.CID),
qm.Returning(...),
)
queries.SetUpdate(q, models.M{"days": pt.Days})
var results models.UserSlice
err := q.Bind(ctx, exec, &results) Does this help? |
Beta Was this translation helpful? Give feedback.
You would likely have to craft this query yourself:
If you only need to update and don't necessarily care about the returned objects:
If you want to return the values:
Does this help?