2016-07-27 5 views
1

私は2つのモデルを持っており、それらの間には多くの関連があります(私は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から任意の値に変更します。あなたの実装コードを共有してより詳細な答えを得る。

関連する問題