Skip to content

Equivalent of Update on Model on non primary key #1423

Answered by stephenafamo
shalabgoel asked this question in Q&A
Discussion options

You must be logged in to vote

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?

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by shalabgoel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants