In sequelize it's possible to create a row and all it's association in one go like this:
return Product.create({
title: 'Chair',
User: {
first_name: 'Mick',
last_name: 'Broadstone'
}
}, {
include: [ User ]
});
Is there a equivalent for update?
I tried
model.user.update(req.body.user, {where: {id: req.user.user_id}, include: [model.profile]})
But it's only updating user
Doing this for create works
model.user.create(user, {transaction: t, include: [model.profile]})
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…