Gorm: Add support for different field name casing

Created on 8 Nov 2016  ·  3Comments  ·  Source: go-gorm/gorm

I use existing DB that uses camel case for field names and snake case for table names. Gorm seems to have hardcoded ToDBName() function that is not customizable.

our table looks like this:

product_skus {
skuId string
}

Most helpful comment

For google users, this can be done now, PR here: https://github.com/jinzhu/gorm/pull/2040

All 3 comments

@jinzhu
Here are the problems with the current approach:

  1. The relationships don't still pick up the metadata for column names (many2many doesn't work).. Check my stackoverflow question here. http://stackoverflow.com/questions/40094666/gorm-many2many-mapping-to-custom-field-names
  2. With large no. of tables, I want to be able to define my casing logic in 10 lines instead of writing metadata on 100s of columns.. This is both painful and error prone.

Also, it is very easy to expose ToDBName() function to be modifiable.

For google users, this can be done now, PR here: https://github.com/jinzhu/gorm/pull/2040

Was this page helpful?
0 / 5 - 0 ratings

Related issues

littletwolee picture littletwolee  ·  3Comments

sredxny picture sredxny  ·  3Comments

easonlin404 picture easonlin404  ·  3Comments

Ganitzsh picture Ganitzsh  ·  3Comments

koalacxr picture koalacxr  ·  3Comments