1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-11 08:30:40 +00:00

orm full remove orm.Manager for simple use, add struct tag - for skip struct field

This commit is contained in:
slene
2013-08-09 20:14:18 +08:00
parent 402932aa6e
commit f2b359d8e8
16 changed files with 161 additions and 301 deletions

View File

@ -11,6 +11,17 @@ orm:"null;rel(fk)"
多个设置间使用 `;` 分隔,设置的值如果是多个,使用 `,` 分隔。
#### 忽略字段
设置 `-` 即可忽略 struct 中的字段
```go
type User struct {
...
AnyField string `orm:"-"`
...
```
#### auto
设置为 Autoincrement Primary Key
@ -49,23 +60,6 @@ type User struct {
...
Status int `orm:"default(1)"`
```
仅当进行 orm.Manager 初始化时才会赋值
```go
func NewUser() *User {
obj := new(User)
obj.Manager.Init(obj)
return obj
}
u := NewUser()
fmt.Println(u.Status) // 1
```
#### choices
为字段设置一组可选的值,类型必须符合。其他值 clean 会返回错误
```go
Status int `orm:"choices(1,2,3,4)"`
```
#### size (string)
string 类型字段设置 size 以后db type 将使用 varchar

View File

@ -17,14 +17,12 @@ type User struct {
Id int `orm:"auto"` // 设置为auto主键
Name string
Profile *Profile `orm:"rel(one)"` // OneToOne relation
orm.Manager // 每个model都需要定义orm.Manager
}
type Profile struct {
Id int `orm:"auto"`
Age int16
User *User `orm:"reverse(one)"` // 设置反向关系(可选)
orm.Manager
}
func init() {