GORM Playground Link

https://github.com/go-gorm/playground/pull/1

问题描述

  1. 定义如下接口 type CommonSyncInstance interface {}

  2. 定义如下model,假定实现了CommonSyncInstance type User struct{}

  3. 调用gorm.db执行创建操作 var ins = []CommonSyncInstance{&User{}} db.Model(&User{}).CreateInBatches(&ins, 100) 由于dst中元素的reflect.kind是Interface,调用Field方法报错

  4. stack schema.(Field).setupValuerAndSetter.func2 (field.go:454) gorm.io/gorm/schema callbacks.ConvertToCreateValues (create.go:230) gorm.io/gorm/callbacks callbacks.Create.func1 (create.go:66) gorm.io/gorm/callbacks gorm.(processor).Execute (callbacks.go:130) gorm.io/gorm gorm.(DB).CreateInBatches.func1 (finisher_api.go:50) gorm.io/gorm gorm.(DB).CreateInBatches (finisher_api.go:60) gorm.io/gorm

  5. 这个问题是否可以优化一下?比如数据同步的业务场景,为了统一流程,定义了抽象接口,公共的流程方法内将数据处理完之后,一般是直接以接口类型调用gorm的方法的。 func CommonMethod(model interface{}, datas []CommonSyncInstance) error { // ... db.Model(model).CreateInBatches(&datas, 100) // ... }

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: 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