Reputation: 195
we are trying to update records in association though sequelize but its only updating the records of model on which it is fired or direct model no associated model affected by the query .
any pathway to perform this
return db.product.findById( 75759,{
include: [
{
model: db.productDescription
}
]})
.then(product => {
var rahulpro = {};
Object.assign(rahulpro,product);
// console.log(rahulpro.product_description.description);
rahulpro.name = "44444";
rahulpro.product_description.dataValues.description = "rahul";
product.updateAttributes(rahulpro);
});
we want to update data of description model
Nothing changed database of description
Database version: mysql 5.7 Sequelize version: 4.8.3
Upvotes: 0
Views: 526
Reputation: 383
I've had a very similar issue using Sequelize. After hours of looking into it, I've seen there is no great way to handle data attached to through tables.
For what you're trying to do, you'll have to perform 2 queries, find the product
instance from your product table, and then query the product_description
table where description.product_id === product.id
.
Then write the changes to the description instance, then to the product instance.
This was a shortcoming of ORM's in my project, and for more complex queries we started using raw sequel because it gave us the ability to do things like this.
Upvotes: 2