Can someone assist with my request? I have a code snippet below:
getData = async (req: Request, res: Response) => {
try {
const data = await FirstModel.findOne({
where: { id: req.params.id },
include: [
{
model: SecondModel,
as: 'secondModel',
},
{
model: ThirdModel,
as: 'thirdModel',
}
],
});
res.json(data);
} catch (err) {
console.error(err);
return res.status(500).json({ error: err.message });
}
}
I am trying to add another piece of data for the fourth model in the object. Here is an example:
data.fourthModel = FourthModel.findAll();
However, I encountered an error message stating:
Property 'fourthModel' does not exist on type 'FirstModel'
.
In addition, I attempted to include one more connection, but it seems that the fourth model is not related to the first.
The desired output should be an object like this:
{
id: 1,
secondModel: {},
thirdModel: {},
fourthModel : {}
}
Any help or guidance would be greatly appreciated!