【发布时间】:2021-10-17 00:51:47
【问题描述】:
我正在尝试按照 Gorm 的 documentation 创建由函数定义的生成字段:
type Foo struct {
ID int64 `json:"id"`
AmountOfBars string `json:"amount_of_bars" gorm:"default:amount_of_bars()"`
}
type RelatedBar struct {
FooId int64 `json:"foo_id"`
}
但是,我不明白在哪里以及如何定义 amount_of_bars,所以我可以返回 RelatedBar 相关行的数量。
【问题讨论】:
-
查看文档中的
uuid_generate_v3()函数,amount_of_bars()函数应该是你的数据库中定义的函数。