gpt4 book ai didi

javascript - 如何使用 Sails JS 中的关联更新模型

转载 作者:行者123 更新时间:2023-11-28 06:50:39 24 4
gpt4 key购买 nike

我正在尝试与具有关联的模型一起工作。我有三个模型:

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' }
}

如果我使用sails lift运行,则会收到错误错误:尝试将集合属性关联到没有外键的模型。 poscustomproduct 类别正在尝试引用 poscustomproduct 中的外键。我试图修复它,但仍然有错误。那么如何修复我的模型呢?

最佳答案

看起来您正在尝试关联一个模型,但无法引用关系,例如您有“主”表,但“辅助”表无法告诉这些项目属于谁......

http://sailsjs.org/documentation/concepts/models-and-orm/associations/one-to-many

关于javascript - 如何使用 Sails JS 中的关联更新模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32983542/

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