nosql模型创建,尝试使用可变产品选项构建产品模式

时间:2017-01-02 09:00:46

标签: node.js total.js nosql

我下载并安装了#34; Totaljs Eshop"并注意到产品创建不允许我定义产品选项(即产品的颜色)。

我进入了NoSQL嵌入式数据库,并查看了models / product.js文件。

我明白了:

NEWSCHEMA('Product').make(function(schema) {

schema.define('id', 'String(20)');
schema.define('pictures', '[String]');
schema.define('reference', 'String(20)');
schema.define('category', 'String(300)', true);
schema.define('manufacturer', 'String(50)');
schema.define('name', 'String(50)', true);
schema.define('price', Number, true);
schema.define('priceold', Number);
schema.define('description', String, true);
schema.define('availability', 'String(40)');
schema.define('template', 'String(30)');
schema.define('body', String);
schema.define('pictures2', '[String]');
schema.define('istop', Boolean);
schema.define('isnew', Boolean);
schema.define('linker', 'String(50)');

我尝试添加以下代码:

schema.define('nicstrength', 'Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)')

我收到错误说:

======= 2017-01-02 02:50:21: Error: Schema: "nicstrength.Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)" not found in "default". Error: Schema: "nicstrength.Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)" not found in "default".
at SchemaBuilderEntity.default (/Users/student/Dev/eshop/node_modules/total.js/builders.js:1138:23)
at SchemaBuilderEntity.get.SchemaBuilderEntity.read (/Users/student/Dev/eshop/node_modules/total.js/builders.js:832:27)
at Controller.$get.Controller.$read (/Users/student/Dev/eshop/node_modules/total.js/index.js:10247:19)
at Controller.json_products_read (/Users/student/Dev/eshop/controllers/api.js:73:7)
at Subscribe.doExecute (/Users/student/Dev/eshop/node_modules/total.js/index.js:9754:23)
at Subscribe.execute (/Users/student/Dev/eshop/node_modules/total.js/index.js:9680:8)
at Subscribe.doAuthorization (/Users/student/Dev/eshop/node_modules/total.js/index.js:9796:8)
at /Users/student/Dev/eshop/node_modules/total.js/index.js:9707:9
at F.onAuthorize (/Users/student/Dev/eshop/models/users.js:324:3)
at Subscribe.prepare (/Users/student/Dev/eshop/node_modules/total.js/index.js:9694:3)

我对后端很新,所以如果这是一个微不足道的问题,我道歉。

这是我的存储库的链接,我分叉了最初的开源项目

https://github.com/akadop/eshop

1 个答案:

答案 0 :(得分:1)

您必须定义正确的架构类型,Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)无效的Total.js架构类型。以下是所有受支持的类型:https://docs.totaljs.com/latest/en.html#api~SchemaBuilder

快速修复:

schema.define('nicstrength', ['0mg', '1.5mg', '3mg', '6mg', '9mg', '12mg']);

因此该字段只需要包含定义值中的一个值。