According to the document and gorm repo's issue,db.Create
is insert record.db.NewRecord
is only check if current value has primary key or not. So do not insert record.
I wrote below this code.
But I could insert record with db.Create
and db.NewRecord
.
What's different between this two methods?
for _, v := range oneday.Onedays {
if err := tx.Create(&v).Error; err != nil {
tx.Rollback()
return model.ResOnedays{}, err
}
// Photos
for i, pv := range v.Photos {
res := tx.NewRecord(&pv)
}
// Tags
for _, tv := range v.Tags {
tx.NewRecord(&tv)
}
}