I've posted this SO question to see if there was a way to handle this:

https://stackoverflow.com/questions/75943586/gorm-createinbatches-with-embedded-struct-error

But, from what I'm finding, when you Create, the insert statement isn't omitting the sub objects if you have the embedded tag on them. Is there a way around this so I can use the embedded tag for SELECT JOINs and not when doing INSERTS?

Comment From: tanzy242

Initially, I thought this would work but it doesn't as gorm doesn't include embedded struct in the schema field names

db.Omit("EmbeddedStruct").Create(&myStruct) // doesn't work

This works but it's not very elegant

db.Omit("embedded_field_1", "embedded_field_2").Create(&myStruct)

My suggestion would be to remove the embedded tag and do SELECT JOINS like this

db.Joins("EmbeddedStruct").Find(&myStruct)

Comment From: a631807682

Currently, when parsing the schema, the embedded information for searching is not marked, even if it has been stored in these places

https://github.com/go-gorm/gorm/blob/32fc2015543c41557a364d45213ca6c710b478bd/schema/schema.go#L29 https://github.com/go-gorm/gorm/blob/32fc2015543c41557a364d45213ca6c710b478bd/schema/field.go#L56

We can optimize SelectAndOmitColumns to support it https://github.com/go-gorm/gorm/blob/32fc2015543c41557a364d45213ca6c710b478bd/statement.go#L689

I'm not sure this is a practical feature, if anyone wants to support this feature, please leave a comment in the issues so it will be listed as a feature.

Comment From: github-actions[bot]

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days