• 用了 gen 之后现在生成的目录如下

  • do

  • entity

  • 如果我要写 hooks, 怎么在 entity 目录之外写 hooks 呢

Comment From: seth-shi

我是要针对 entity 下的某个模型, 创建的时候要生成 uuid

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: kuangshp

我是要针对 entity 下的某个模型, 创建的时候要生成 uuid

你那边处理了吗,我也遇到这样的,但是最后用全局插件写的

Comment From: seth-shi

没找到解决方法

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: paradox-lab2

这在go语言层面上就不支持实现吧,结构体方法只能定义在同一个包内

Comment From: seth-shi

这在go语言层面上就不支持实现吧,结构体方法只能定义在同一个包内

很多种方式可以实现, 比如提供一个注册方法



gorm.RegisterHooks(&Model{}, "created", func (m Model) {
      // xxxx
})


gorm.RegisterHooks(&Model{}, func (m Model) {
      m.Saving(function () {
             // xxxx
       })
})

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking