1
두 모델이 있고 그들 사이에 많은 연관이 있습니다 (sails.js 프레임 워크를 사용하고 있습니다). 연관 테이블에 추가 필드를 추가했습니다. 추가 필드를 채우고 싶습니다. 이것을 어떻게 성취합니까? 추가 필드의 가격을 채우는 방법을 은 돛에 'through'표의 추가 정보를 채 웁니다.
module.exports = {
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
storeID: {
model: 'stores'
},
productID: {
model: 'product'
},
price: 'integer' //I want to populate this additional field when calling api '/product' or '/store'
}
};
Price.js
을 내 Product.js이//Product.js
module.exports = {
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
name: 'string',
storeID: {
collection: 'stores',
via: 'productID', //This is for association with the Store model
through: 'price'
}
}
};
파일입니다 아래
//Store.js file
module.exports = {
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
name: "string",
slug: "string",
imageURL: "string",
termsAndConditions: "string",
link: "string",
productID: {
collection: 'product', //This is for association with the product model
via: 'storeID',
through: 'price'
}
}
};
그리고 아래 모델을 통해 내입니다 : 내 모델 아래에서 언급 Api '/ product'또는 '/ store'를 호출 할 때 가격 표가 필요합니까?