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

示例错误 #15

Closed
js2854 opened this issue Oct 1, 2020 · 1 comment
Closed

示例错误 #15

js2854 opened this issue Oct 1, 2020 · 1 comment
Labels
Documentation Improvements or additions to documentation

Comments

@js2854
Copy link

js2854 commented Oct 1, 2020

代码示例有明显的错误

// 用法一,使用carbon.GormModel自动维护id、created_at、updated_at、deleted_at
type User struct {
	carbon.GormModel
	Name string `json:"name"`
	Age int `json:"age"`
	Birthday carbon.ToDateTimeString `json:"birthday"`  
}
user := User {
    Name: "勾国印"
    Age: 18
    Birthday: "2012-09-09 00:00:00" // 这里字符串无法赋值给ToDateString类型,结构体赋值也缺少必要逗号
}

// 用法二,不使用carbon.GormModel
type User struct {
	Name string `json:"name"`
	Age int `json:"age"`
	Birthday carbon.ToDateString `json:"birthday"`
	CreatedAt carbon.ToDateTimeString `json:"created_at"`
	UpdatedAt carbon.ToTimeString `json:"updated_at"`
	DeletedAt carbon.ToTimestamp `json:"deleted_at"`
}
user := User {
    Name: "勾国印"
    Age: 18
    Birthday: "2012-09-09 00:00:00" // 这里字符串无法赋值给ToDateString类型,结构体赋值也缺少必要逗号
}

另外在使用gorm时, carbon.ToDateString类型的字段无法直接赋值carbon.New().Now(),两者之间的转换无法无缝衔接
貌似跟直接用time.Time唯一的区别就是支持了几种不同的时间格式

@gouguoyin
Copy link
Member

对orm的支持已优化,详情见说明文档

@gouguoyin gouguoyin added the Documentation Improvements or additions to documentation label Jul 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation
Development

No branches or pull requests

2 participants