8000 proposal: allow specifying extra constraints on UpdateOne and DeleteOne instances via Where() · Issue #849 · ent/ent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
proposal: allow specifying extra constraints on UpdateOne and DeleteOne instances via Where() #849
Closed
@DeedleFake

Description

@DeedleFake

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0