Pyae Phyoe Shein
Pyae Phyoe Shein

Reputation: 13787

how to update all records with updateAttributes in postgres sequelize

I want to update all records meet our criteria with updateAttributes in postgres sequelize.

deactivateJobsByCompany(companyData.id, {transaction: t}).then(function(jobs) {
    jobs.updateAttributes({is_active: false}, {transaction: t}).then(function () {
        onSuccess(company);
    })
});

I don't know why jobs.updateAttributes got error. Please let me know how to solve it. Thanks.

Upvotes: 0

Views: 5218

Answers (1)

Shivam
Shivam

Reputation: 3622

You can use the update method, something like

Model.jobs.update({is_active:false},
{where:{company_id:Id}})

Also updateAttributes works on an model instance, is the jobs returned by deactivateJobsByCompany a model instance

If it returns an array of jobs, you might need to call updateAttributes on each of them.

Upvotes: 1

Related Questions