以下是我的风帆模型,每当我尝试保存()时,我都会收到以下错误
[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: ''}
}
}
};
答案 0 :(得分:2)
您无法使用Sails / Waterline ORM嵌套数据。问题出在meta : {}
位。因此,就风帆而言,您已经定义了一个名为meta
的属性,并且正在尝试应用名为type : 'string'
等的规则(例如address, city, mobile, email
),这些都不是有效的规则
我建议您创建一个名为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: '' }
}
};
请参阅sails attributes了解您能够或不能放入模型说明