Optional arguments and patch
I read that setting a field to undefined with
db.patch
unsets it. now I'm a bit afraid of implementing an "update" function that can update any values if you provide a value for them:
is this safe if I make the args optional?3 Replies
In your code example args.email will be unset, so when you try to access it you will get undefined, and so the email would be unset.
With patch you probably want
ctx.db.patch(id, args)
Now the fields that are unset won’t change the document fields in the db.
^ this but you probably want
const {id, ...updates} = args; await ctx.db.patch(id, updates)
oh okay, thanks!