Question about camel/snake case for key columns

17 views
Skip to first unread message

Jake Malone

unread,
Jan 11, 2016, 5:55:22 PM1/11/16
to Sequelize
Hi,
I'm new to Sequelize, and love it so far, but I have a question regarding case with key names. My apologies if this information is in the docs, I couldn't find it.

In MySQL, my column names are underscored. In my models, I use camel case properties and map to the underscored name using field. But when there's an association, how do I specify that I want camel case for the key column (which is not defined in the model since it's an auto column)?

For example, let's say I have a Users model, and Users belong to Groups. When I select Users, I'd like them to contain a groupId property instead of group_id.

Possible?

Thanks in advance!

Jake Malone

unread,
Jan 11, 2016, 5:57:36 PM1/11/16
to Sequelize
To clarify my Users/Groups example, if it helps, I'm talking about a one-to-many. Users only belong to one Group.

Mick Hansen

unread,
Jan 12, 2016, 2:38:31 PM1/12/16
to Jake Malone, Sequelize
Hi Jake,

To achieve this you should define the foreign key on the model with the `field` prop and then have the foreignKey property of the association setup map to the foreign key name on the model.
--
Mick Hansen
@mhansendev
mhansen.io
Reply all
Reply to author
Forward
0 new messages