By default, Sequelize (an ORM system for NodeJS) only allows you to specify custom table name. Currently, there is no such feature in Sequelize to help you define custom column names and then map them to properties in model objects. To achieve this, you may need a workaround that is to use getter and setter methods provided by Sequelize. When you creating the model, set the property names to the same with the corresponding column name in database first. After that, define the setter and getter functions to map those column to the desired properties name that you want. This example transforms model properties name from snake_case (SQL style) to camelCase (JS style).
Later, when you want to create a new instance, you can use the
As you can see, this solution still has one drawback, that is the the two
properties exists at the same time inside the
People model. But at least, this
works! Let’s wait for Sequelize to add this functionality in the future.