Description
The Where()
method is only available for Update
and Delete
, not for UpdateOne
and DeleteOne
, but it would be quite useful to be able to use it on those simply as a way of specifying extra constraints. For example, let's say that you have two entities, A
and B
, where A
has an edge to B
but that edge is unique the other direction. The user wants to update a B
belonging to a certain A
. Currently, the only way to ensure that the user's input is correct for both IDs is to use an Update
, such as
n, err := entc.B.Update().
Where(b.ID(bid)).
Where(b.HasAWith(a.ID(aid))).
SetSomeField(something).
Save(ctx)
and then manually check if n
is in fact one. It would be convenient to be able to do
b, err := entc.B.UpdateOneID(bid).
Where(b.HasAWith(a.ID(aid))).
SetSomeField(something).
Save(ctx)
instead and let it properly fail with a ent.IsNotFound(err) == true
error if nothing with that condition exists. Not to mention that this will return the updated entity, too.