0
我在两个表(产品和服务)之间建立了多对多关系,它通过连接表与成本列product_service关联。当我创建尝试向产品添加服务时,即使数据库已更新,第一次调用也不会返回更新后的值,但我知道,因为我检查了它,只能在我的应用程序中查看更新后的值另一个电话。NodeJS Sequelize:关联设置值的问题
var query = {
where: {
id: req.params.id
},
include: defaultIncludes()
}
models.products.findOne(query)
.then(function (product) {
if (!product) {
return res.status(404).json({message: 'Product not found' });
} else {
this.product = product;
return models.services.findById(req.body.service_id);
}
})
.then(function (service) {
return this.product.addServices(service);
})
.then(function (result) {
return this.product.save();
// return models.products.findOne(query);
})
.then(function (product) {
return res.status(200).json(product)
})
.catch(function (err) {
logger.error(err);
return res.status(500).json({error: err.message});
});
我认为它可能与承诺,addServices或保存功能,但我似乎无法弄清楚。