'Sequelize nested transactions is not working correctly
Im not able to post in database a sequelize nested post. I have a n:1 relationship between tab and section. 1 Tab may have multiples sections. The body of the request is something like this:
tab = {
name: 'name',
position: 0,
process_id: 266,
descriptor_f: 'NAME',
section: [{
name: 'New Sec',
process_id: 266,
position: 0,
},
{
name: 'New Sec2',
process_id: 266,
position: 1,
}
]
}
It could happend that comes multiples tabs. Tabs and Sections are two diferent models of my db. Im tring to work with nested transactions like this but just the Tab is getting posted on my db.
const formPost = async (req = request, res = response) => {
try {
const { form } = req.body;
if (form.tabs.length > 0) {
for (const tabb of form.tabs) {
const tab = await Tab.create(
{
name: tabb.name,
position: tabb.position,
process_id: tabb.process_id,
created_by: tabb.created_by,
descriptor_f: tabb.descriptor_f,
section,
},
{
include: Section,
}
);
console.log(tab);
console.log(tabb);
}
}
console.log(form, res);
return null;
} catch (err) {
console.log(err);
return err;
}
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
