Reputation: 3
I'm trying delete one record, via destroy method of an instance.
const memCustomers = await Customers.findAll({ limit: 10 })
for (const customer of memCustomers ) {
//do things
await customer.destroy()
}
But when i use this command it delete all records in table customers, and when i add "where" argument for destroy method, nothing change...
I set logging equal true... and it show a "delete from table" without "where".
Upvotes: 0
Views: 918
Reputation: 4923
You have two options:
const customers = await Customers.findAll({ where: …, limit: … })
Promise.all(customers.filter( … ).map(customer => customer.destroy()))
const customers = await Customers.findAll({ where: …, limit: … })
await Customers.destroy({ where: … })
This highly depends on the number of entries but I would always recommend doing the filtering on the database level
Upvotes: 0