I need a UUID field in a content type, with the help of the introduction below I have modified the file "MyType.settings.json".
https://strapi.io/documentation/3.x.x/guides/models.html#define-the-attributes
"uid": {
"default": "",
"type": "uuid"
},
I thought a UUID is automatically saved, but nothing happens.
How can I define and use a UUID field? Can someone give me a hint? Should I also modify the file \api\MyType\controllers\MyType.js?
Thanks in advance!
Benjamin
What is a UUID. Universally Unique Identifiers, or UUIDS, are 128 bit numbers, composed of 16 octets and represented as 32 base-16 characters, that can be used to identify information across a computer system.
Overview of the UUID data type. A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. You can create a UUID and use it to uniquely identify something.
UUIDs are constructed in a sequence of digits equal to 128 bits. The ID is in hexadecimal digits, meaning it uses the numbers 0 through 9 and letters A through F. The hexadecimal digits are grouped as 32 hexadecimal characters with four hyphens: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.
To generate a single UUID, run the uuidgen command without any arguments. Out of the box, uuidgen will generate a random UUID each time it runs. Execute the following command in your terminal: uuidgen.
You will have to use uuid
node module.
So keep your attribute and in the lifeCyle functions, set your uuid
with the lib.
'use strict';
const uuid = require('uuid');
module.exports = {
beforeCreate: async (model) => {
model.set('uid', uuid());
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With