Closed
Description
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
Projects
Status
✅ Done