Add another method of setting table name. #89

Closed
opened 8 years ago by ahall · 0 comments
ahall commented 8 years ago (Migrated from github.com)
Owner

At the moment if your table name is not the same as the class name you got to set it for every single operation e.g.: session.Table("users").Find(&users). Would be nice if you could set it on the struct such as:

type User struct {
Id int64 xorm:"id"
UserName string xorm:"username"
FullName string xorm:"full_name"
}

func (this User) TableName() {
return "users"
}

I like the idea of declaring the table once and then using the fields instead of stating table and column names and use Go's type system. It makes it easier to rename columns in the future and make the compiler help you catch references to it.

At the moment if your table name is not the same as the class name you got to set it for every single operation e.g.: session.Table("users").Find(&users). Would be nice if you could set it on the struct such as: type User struct { Id int64 `xorm:"id"` UserName string `xorm:"username"` FullName string `xorm:"full_name"` } func (this User) TableName() { return "users" } I like the idea of declaring the table once and then using the fields instead of stating table and column names and use Go's type system. It makes it easier to rename columns in the future and make the compiler help you catch references to it.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.