When using the save to map feature, and specifying a model type that includes the table's PK, the code always panics. When the model type does not include the PK column, it works.
Line 234 in FindInBatches() executes code to deal with the PK, calling line 462 in setupValuerAndSetter(). Line 462 in setupValuerAndSetter() is the culprit. It invokes v.Field() assuming v is the struct instance being populated, but in this case v is the map (see the three attached screen shots). Line 1278 in reflect.Field() is being asked to look at a field in the provided struct, but it's not a struct, it's a map.
This fails (after returning from the anonymous function and landing back in FindInBatches): type Id struct { Id string // This maps to the table PK } db.Model(&Id{}).Table("table_with_id_as_pk").Where(find).FindInBatches(&rows, 500, func(db gorm.DB, batchID int) error { for _, row := range rows { ... } return nil }) This works: type OtherCol struct { OtherCol string } db.Model(&OtherCol{}).Table("table_with_id_as_pk").Where(find).FindInBatches(&rows, 500, func(db gorm.DB, batchID int) error { for _, row := range rows { ... } return nil }) As identified in a separate ticket is the apparent bug that requires any model object at all, when a map is used as a destination. Screenshots: Screen Shot 2024-03-15 at 8 19 31 AM

Screen Shot 2024-03-15 at 8 06 33 AM

Screen Shot 2024-03-15 at 8 07 01 AM

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

I don't see the operation of save to map in the demo? @ccrenshawSSS

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