ent
ent copied to clipboard
Fix IDs() to respect mutation predicates for UpdateOne and DeleteOne
Fixes issue #3883
Summary
Updated the generated IDs()
function on mutations.
Checks during OpUpdateOne
and OpDeleteOne
if there are any predicates set on the mutation and if yes, adds another predicate with the id of the mutation and runs it against the database to see if the ID is still included after all predicates have been applied.
In case there are no predicates defined, the old behaviour is kept and directly returns the id (to save a query).
@a8m looking forward to your review 👀
@a8m any update on this?
@a8m any update on this?
Mutation should not be tested inside hooks. Instead, create a builder and then call Mutation()
- The assertions should apply on this object. If this requires too much time, just clean the tests and one of the team will take it.
You can add a simple case to this function: https://github.com/ent/ent/blob/master/entc/integration/integration_test.go#L2122
Saw the failed CI report. Forgot to run generate for the examples directory as well. Should be fixed now :)
Hey @a8m, any chance we can get this merged. Just synced with master again and ran all generate + mod tidy as well as tests. Hopefully should pass CI now :)