Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Delete route, .remove not a function?

I´ve created a route to delete a product but when I try to run it, I get the error .remove is not a function. I don't know why this is occurring or how to fix it, I have looked only haven't found anything that works. My route looks like this:

orderRouter.delete(
    '/:id',
    isAuth,
    isAdmin,
    expressAsyncHandler(async (req, res) => {
        const order = await Orderline.findByPk(req.params.id);
        if (order) {
            const deletedOrder = await order.remove();
            res.send({ message: 'Order Deleted', product: deletedOrder });
        } else {
            res.status(404).send({ message: 'Order Not Found' });
        }
    })
);

Any guidance/help is much appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In Sequelize ORM, Instance.remove() is not a function. Use Instance.destroy() instead.

Refer to the documentation about it here

So your fixed code would be:

orderRouter.delete(
    '/:id',
    isAuth,
    isAdmin,
    expressAsyncHandler(async (req, res) => {
        const order = await Orderline.findByPk(req.params.id);
        if (order) {
            const deletedOrder = await order.destroy();
            res.send({ message: 'Order Deleted', product: deletedOrder });
        } else {
            res.status(404).send({ message: 'Order Not Found' });
        }
    })
);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!