2017-01-22 64 views
1

以下是我的帆模型,每當我試圖挽救()我收到以下錯誤sailsjs類型對象的模型屬性,可能嗎?

[Error: Unknown rule: address] 

使用與貓鼬同類機型,沒有任何問題,可能有人看到我的模型中的任何錯誤嗎?

謝謝!

/** 
* 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: ''} 
     } 

    } 
}; 

回答

1

不能使用Sails/Waterline ORM嵌套數據。問題在於meta : {}位。所以就帆而言,你已經定義了一個名爲meta的屬性,並試圖應用一個規則(如type : 'string'),稱爲address, city, mobile, email等,這些都不是有效的規則。

我建議你要麼創建一個叫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