Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Naming Strategy - not unique table names #6833

Closed
f3oall opened this issue Feb 7, 2024 · 2 comments
Closed

Custom Naming Strategy - not unique table names #6833

f3oall opened this issue Feb 7, 2024 · 2 comments
Assignees
Labels
type:question general questions

Comments

@f3oall
Copy link

f3oall commented Feb 7, 2024

Your Question

When I implement custom Namer interface for NamingStrategy

type Namer interface {  
  TableName(table string) string   
  SchemaName(table string) string  
  ColumnName(table, column string) string  
  JoinTableName(table string) string 
  RelationshipFKName(Relationship) string  
  CheckerName(table, column string) string  
  IndexName(table, column string) string
}

table parmater is a type name without the package prefix (e.g. User instead of users.User), so how should I distinguish one table from another?

Also when trying to override table name manually during the query:

db.Table("test").First(&User{})

The table param is User and not the test. Is it an expected behaviour?

The document you expected this should be explained

Expected answer

@f3oall f3oall added the type:question general questions label Feb 7, 2024
@jinzhu
Copy link
Member

jinzhu commented Feb 8, 2024

The table param is User and not the test. Is it an expected behaviour?

No, it should be test

table parmater is a type name without the package prefix (e.g. User instead of users.User), so how should I distinguish one table from another?

We don't care which package is it from, if package distinction is important in your case, perhaps you want to refer to https://gorm.io/docs/conventions.html#TableName

@jinzhu jinzhu closed this as completed Feb 8, 2024
@f3oall
Copy link
Author

f3oall commented Feb 8, 2024

No, it should be test

Should I open a bug report then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

2 participants