The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Sequelize: Model & Column Casing

Sequelize: Model & Column Casing

2:38
Javascript and database systems tend to be at odds with regard to how tables and columns should be named. Sequlize provides all the tools necessary to satisfy naming conventions in both your Node.js code and in your SQL database.
Watch this lesson now
Avatar
egghead.io

Javascript and database systems tend to be at odds with regard to how tables and columns should be named. Sequlize provides all the tools necessary to satisfy naming conventions in both your Node.js code and in your SQL database.

Avatar
Olga

Name conversion between tables and js objects drives me crazy in Sequelize. Often I have to use quite complex SQL queries, where I have to use 'query' method. The result from query has keys underscored. Does Sequelize provide any helper to convert them to camelCased version ? Right now, I just give an aliases to columns in SQL queries, but it seems tedious. There are also solutions like: https://github.com/domchristie/humps, but still I wonder if there is any better way to do it.

In reply to egghead.io
Avatar
Mike

There is an underscored option on the sequelize.define options object, but it does not do what the documentation says.

The docs state "Converts all camelCased columns to underscored if true", however, that only appears to be for Sequelize generated fields, such as timestamps and foreign keys.

Setting underscoredAll to true will also set underscored to true.

In reply to Olga
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?