Add another method of setting table name. #89

Closed
opened 2014-04-08 07:19:13 +00:00 by ahall · 0 comments
ahall commented 2014-04-08 07:19:13 +00:00 (Migrated from github.com)

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
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#89
No description provided.