When attempting to retrieve items from the database based on their id
, I am encountering an issue where Insomnia is returning an empty object. Specifically, in the code snippet below, my goal is to fetch a category by its ID while also retrieving any associated Products.
Could you possibly point out what I might be overlooking here? Thank you for your help!
router.get('/:id', async (req, res) => {
try {
const oneCategory = await Category.findByPk({
include: [{ model: Product }]
});
// console.log(oneCategory);
if (!oneCategory) {
res.status(404).json({ message: 'No category found with that id!' });
return;
}
res.status(200).json(oneCategory);
} catch (error) {
res.status(500).json(error);
}
});