Assign Reference Field to Order Document with Characters from ID Field

1 replies
Last updated: Jun 5, 2022
How would I make sure each Order document created is automatically assigned a
reference
field that is basically the last 6 characters of the generated
_id
field, uppercased?My sense told me that I should replace the
client.create(order)
with something like
client.transactiion().create(...).patch(<id of order just created>, <functionToAddReference>)
but the issue is that I don't know the
_id
of the just created order, or is there a way to pass it to the patch function?Or perhaps I should just handle the ID generation myself, this way I can perform manipulations on it and provide the
reference
directly in the
create
The point is that I want to avoid making two API calls for dealing with this. Is that possible?
Jun 5, 2022, 10:59 AM
Got myself sorted with nanoid and a custom alphabet
Jun 5, 2022, 2:21 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in