8000 ✨ [Feature] Configure camel case columns instead of snake case GORM · Issue #477 · goravel/goravel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
✨ [Feature] Configure camel case columns instead of snake case GORM #477
Closed
goravel/framework
#773
@dusanbre

Description

@dusanbre

Before feedback (在反馈之前)

  • I've searched the existing Issues, Discussions and Google (我已经搜索了现有的 Issues, Discussions 和 Google)
  • The problem can be stably reproduced (这个问题可以被稳定复现)
  • The problem is generated after upgrading (问题是在升级之后产生的)

Operating System (操作系统)

MacOS

Golang Version (Go 版本)

1.21.x

Goravel Version (Goravel 版本)

1.14.4

Describe The Problem (描述问题)

This is a maybe more of feature request or hidden feature that i can not find how to configure.
Problem is with many2many relation and camel cased column names.

Db structure:

restaurants:

  • id
  • name

category:

  • id
  • name

restaurant_categories:

  • id
  • restaurantId
  • categoryId

Categories []Category gorm:"many2many:restaurant_categories;foreignKey:id;joinForeignKey:restaurantId;References:id;joinReferences:categoryId" json:"categories"

Gorm allows to change foreign keys names, etc.. but when i try to change it this restaurantId gorm converts this into restaurant_id and than throws invalid column name

Also gorm allows to configure naming strategy but i can not find way to configure this throught Facades


db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{  
NamingStrategy: schema.NamingStrategy{    
TablePrefix: "t_",   // table name prefix, table for `User` would be `t_users`    
SingularTable: true, // use singular table name, table for `User` would be `user` with this option enabled    
NoLowerCase: true, // skip the snake_casing of names    
NameReplacer: strings.NewReplacer("CID", "Cid"), // use name replacer to change struct/field name before convert it to db name  
},})
--

Can you help with this?

Thanks

Reproduction Code (复现代码或截图)

// Your code here

Metadata

Metadata

Assignees

Type

No type

Projects

Status

✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    < 2AB3 /div>
    0