1
我正在尝试使用关联模型。我有三个型号:如何更新SailJS中的关联模型
PosProductCategory.js
module.exports = {
schema : true,
attributes: {
name : {type : 'string', required : true },
desc : {type : 'text', required : true },
// assets
products : { collection : 'PosProduct', via : 'category' },
productsCustomize : { collection : 'PosCustomProduct', via : 'category' },
display : { model : 'CmsProductCategory' },
// available spec & template attribute
availableSpecification : { type : 'array' },
templateAttribute : { type : 'array' },
// store referrer
store : { model : 'SystemStore' }
}
};
PosProduct.js
module.exports = {
schema : true,
attributes: {
name : { type : 'string', required : true },
desc : { type : 'text' },
basePrice : { type : 'integer' , required : true },
// category
category : { model : 'PosProductCategory'},
// tags
// { "text": {string} }
tags : { collection : 'PosProductTag', via : 'products', dominant: true},
// attributes
attributes : { type : 'object' },
// specification
specification : { type : 'object' },
// materials (donwlodable material/attachment)
// { name : {string}, file: {string}, notes : {text} }
materials : {type : 'array'},
// publishment
published : { type : 'boolean', defaultsTo: false },
// assets
display : { model : 'CmsProduct' },
// store referrer
store : { model : 'SystemStore' }
}
};
PosCustomProduct.js
module.exports = {
schema : true,
attributes: {
name : { type : 'string', required : true },
basePrice : { type : 'integer' , required : true },
//category
category : { model : 'PosProductCategory'},
//variant
attributes : { type : 'object' },
//gambar setiap sisi
materials : { type : 'object' },
// publishment
published : { type : 'boolean', defaultsTo: false },
// assets
display : { model : 'CmsCustomProduct' },
// store referrer
store : { model : 'SystemStore' }
}
如果我运行使用帆升降机,我得到了一个错误错误:试图将集合属性关联到没有Foregn键的模型。 poscustomproduct类正试图引用poscustomproduct中的外键。我试图修复它,但它仍然有一个错误。那么如何解决我的模型?