gpt4 book ai didi

node.js - 类型对象的 sailsjs 模型属性,可能吗?

转载 作者:可可西里 更新时间:2023-11-01 09:14:02 26 4
gpt4 key购买 nike

以下是我的 sails 模型,每当我尝试 save() 时,我都会收到以下错误

[Error: Unknown rule: address]

曾经有与 mongoose 相似的模型,没有任何问题,有人可以看到我的模型中有任何错误吗?

谢谢!

/**
* Users.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models
*/

module.exports = {

connection: 'MongoServer',

attributes: {
AcctSessionId: {type: 'string', required: false, default: ''},
UserName: {type: 'string', required: true, unique: true},
UserPassword: {type: 'string', required: true},
AcctStartDelay: {type: 'string', required: false, default: ''},
AcctStopDelay:{type: 'string', required: false, default: ''},
AcctPlan: {type: 'string', required: false, default: ''},
AcctResellerID: {type: 'string', required: false, default: ''},
AcctPrice: {type: 'integer', required: false, default: ''},
AcctCurrency: {type: 'string', required: false, default: 'LBP'},
AcctEnabled: {type: 'boolean', required: false, default: true},
AcctExpiry: {type: 'boolean', required: true},

meta: {
address: {type: 'string', required: false, default: ''},
city: {type: 'string', required: false, default: ''},
mobile: {type: 'integer', required: true, default: ''},
email: {type: 'string', required: false, default: ''},
name: {type: 'string', required: true, default: ''}
}

}
};

最佳答案

您不能像使用 Sails/Waterline ORM 那样嵌套数据。问题出在 meta : {} 位。因此,就 sails 而言,您已经定义了一个名为 meta 的属性,并且正在尝试应用一个名为 的规则(例如 type : 'string')地址、城市、手机、电子邮件等,这些都不是有效的规则。

我建议您创建一个名为addressuserMeta 或类似名称的新模型,然后输入address、city、mobile、email等等。然后将它们关联起来,或者,干脆去掉 meta : {} 包装器,就这样......

/**
* Users.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models
*/

module.exports = {

connection: 'MongoServer',

attributes: {
AcctSessionId: { type: 'string', required: false, default: '' },
UserName: { type: 'string', required: true, unique: true },
UserPassword: { type: 'string', required: true },
AcctStartDelay: { type: 'string', required: false, default: '' },
AcctStopDelay: { type: 'string', required: false, default: '' },
AcctPlan: { type: 'string', required: false, default: '' },
AcctResellerID: { type: 'string', required: false, default: '' },
AcctPrice: { type: 'integer', required: false, default: '' },
AcctCurrency: { type: 'string', required: false, default: 'LBP' },
AcctEnabled: { type: 'boolean', required: false, default: true },
AcctExpiry: { type: 'boolean', required: true },

address: { type: 'string', required: false, default: '' },
city: { type: 'string', required: false, default: '' },
mobile: { type: 'integer', required: true, default: '' },
email: { type: 'string', required: false, default: '' },
name: { type: 'string', required: true, default: '' }
}
};

参见 sails attributes对于您可以或不能放在模型描述中的内容

关于node.js - 类型对象的 sailsjs 模型属性,可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41795602/

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