types对象的sailsjs模型属性,可能吗?

以下是我的帆模型,每当我尝试保存()我得到以下错误

[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: ''} } } }; 

       

网上收集的解决方案 "types对象的sailsjs模型属性,可能吗?"

你不能使用Sails / Waterline ORM来嵌套数据。 问题在于meta : {}位。 所以就帆而言,你已经定义了一个名为meta的属性,并试图应用一个称为address, city, mobile, email等的规则(比如type : 'string' ),这些规则都不是有效的。

我build议你要么创build一个叫做address的新模型,要么是userMeta或类似的东西,把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: '' } } }; 

查看您可以或不可以放入模型描述的帆的属性