Answer the question
In order to leave comments, you need to log in
How to delete related data?
I am using Sequelize ORM. And I want to make sure that all attached data is deleted. But at the moment, information is deleted only from the first table, and only the foreign key is deleted from the table linked by id, while the information itself remains.
const db = require('../config/db.config.js')
const SprWellplatforms = db.spr_wellplatforms
const SprOilfield = db.spr_oilfields
const errorHandler = require('../utils/errorHandler')
module.exports.remove = async function(req, res) {
try {
await SprOilfield.destroy({
where : {
oilfield_id: req.params.id
}
})
await SprWellplatforms.destroy({
where: {
spr_oilfields_id: req.params.id //spr_oilfields_id - это foreign key
}
})
res.status(200).json({
message: 'Данные удалены.'
})
} catch(e) {
errorHandler(res, e)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question