2016-07-27 29 views
1

我有兩個模型,它們之間有很多關聯(我使用的是sails.js框架)。我在關聯表中添加了添加字段。我想填充該添加字段。我如何實現這一目標?我的模型給出如下:在帆中填充'through'表的其他信息

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

下面是我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' 
} 
} 
}; 

而下面是我通過模型Price.js

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

如何填充附加字段價格價格表從調用api'/ product'或'/ store'?

回答

0

在填充(執行或取決於您的實現)後的回調函數內部在價格表中查找記錄並對該記錄執行更新以將價格的值從null更改爲任何您需要的值。分享您的實施代碼以獲取更詳細的答案。