Creating a new record on an associated table needs first letter to be upper case (UserId) #16955
-
Hello everyone: I'm working on a project using NodeJS 18, Sequelize (6.35.2) and Postgres (8.11.3) and I'm getting this weird behavior. But first, here are the models... user.js
user_reset_token.js
And then, I create the UserResetToken record like this:
Notice the UserId with the capital U. If I try doing userId, I get the record with a null value in the column. I would love to do all of this just using camelCase, I also tried using underscored: true but the problem persists. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In Sequelize 6, foreign key attributes are prefixed by the target model name, so usually is capitalized. You can use a custom name like this: https://sequelize.org/docs/v7/associations/belongs-to-many/#foreign-keys-names In Sequelize 7, we make the generated foreign key |
Beta Was this translation helpful? Give feedback.
In Sequelize 6, foreign key attributes are prefixed by the target model name, so usually is capitalized. You can use a custom name like this: https://sequelize.org/docs/v7/associations/belongs-to-many/#foreign-keys-names
In Sequelize 7, we make the generated foreign key
camelCase
instead ofPascalCase