sequelize / sequelize/sequelize

Increment with object does not respect field names

Open
#12,512 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
TypeScript
Stars
30.4k
Forks
4.3k
Avg merge
1d 6h
Merged PRs (30d)
68

Description

Issue Description

When incrementing multiple fields using the object syntax, the field names are not transformed (eg to underscore), causing an error since the column doesn't exist. This is a regression from version 5.

What are you doing?
class MyModel extends Model {}
MyModel.init({
  works: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
  },
  longerField: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
  },
}, {
  sequelize,
  modelName: 'MyModel',
  underscored: true,
})

await MyModel.increment({
  works: 1,
  longerField: 1,
});
// SequelizeDatabaseError column "longerField" does not exist

// While this works:
await MyModel.increment("longerField")
await MyModel.increment(["works", "longerField"])
What do you expect to happen?

It should convert to the correct field names and increment the right columns.

What is actually happening?

We get a SequelizeDatabaseError column "longerField" does not exist

Environment
  • Sequelize version: 6.3.3
  • Node.js version: 12.18.2
  • Operating System: OSX 10.15.4

Issue Template Checklist

How does this problem relate to dialects?
  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the MyModel.increment entry point and reproduce the issue with the object syntax from the report, using the underscored model fields. Trace how the object field names reach the database and add coverage for longerField; done means the object form increments the mapped columns without the reported SequelizeDatabaseError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, sql, typescript
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.