【问题标题】:populate additional information of the 'through' table in sails在sails中填充“通过”表的附加信息
【发布时间】:2016-07-27 07:49:50
【问题描述】:

我有两个模型,它们之间有很多对多的关联(我使用的是sails.js 框架)。我在关联表中添加了添加字段。我想填充那个添加字段。我如何实现这一目标?我的模型如下:

//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' 填充 Price 表的附加字段 price?

【问题讨论】:

    标签: sails.js populate


    【解决方案1】:

    填充后的回调函数内部(执行或然后取决于您的实现)在价格表中找到记录并对该记录执行更新以将价格的值从空值更改为您想要的任何值。分享您的实现代码以获得更详细的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 2012-02-07
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 2017-10-10
      • 1970-01-01
      相关资源
      最近更新 更多