2016-07-27 2 views
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'를 호출 할 때 가격 표가 필요합니까?

답변

0

채우기 후 콜백 함수 (exec 또는 구현에 따라 다름) 가격 테이블에서 레코드를 찾고 해당 레코드에 대한 업데이트를 수행하여 가격 값을 null에서 원하는 값으로 변경하십시오. 보다 자세한 답변을 위해 구현 코드를 공유하십시오.

관련 문제