gpt4 book ai didi

strapi - 如何定义和使用 UUID 字段?

转载 作者:行者123 更新时间:2023-12-04 11:24:13 25 4
gpt4 key购买 nike

我需要一个内容类型的 UUID 字段,在下面介绍的帮助下,我修改了文件“MyType.settings.json”。

https://strapi.io/documentation/3.x.x/guides/models.html#define-the-attributes

"uid": {
"default": "",
"type": "uuid"
},

我以为 UUID 会自动保存,但没有任何 react 。

如何定义和使用 UUID 字段?有人可以给我一个提示吗?
我还应该修改文件\api\MyType\controllers\MyType.js 吗?

提前致谢!

本杰明

最佳答案

您必须使用 uuid节点模块。
所以保持你的属性,在 lifeCyle 函数中,设置你的 uuid与库。

'use strict';

const uuid = require('uuid');

module.exports = {
beforeCreate: async (model) => {
model.set('uid', uuid());
}
};

关于strapi - 如何定义和使用 UUID 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56397597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com