-
Notifications
You must be signed in to change notification settings - Fork 114
Closed
Labels
Description
I have some resources whose IDs are integers auto-generated by the database server. I declare them as:
jsonApi.define({
resource: 'Order',
attributes: {
id: jsonApi.Joi.number().integer(),
// Other attributes
},
handler: customHandler,
})
This causes a problem when I try to create a new ID: a UUID is automatically generated, but then fails validation because it is not an integer.
I therefore propose a new key in the resource definition, generateId
, which can be set to false
to disable autogenerating IDs. I have implemented this on my branch create-generate-id, and it is working well for my use so far.
In the future this key could also be extended to take a function which returns an ID, so a project could define its own ID generation scheme. (For example using shortid
; or perhaps even a content-addressable system where a data property is hashed to generate the ID.)
Ayelit and aledalgrande