Gorm has a FirstOrCreate method and a FirstOrInit but how to check afterwards if the record was actually created? I like to create a record if it d
FirstOrCreate
FirstOrInit
The most upvoted answer did not work for me, but this did:
user := NewUser(email, password) if db.Model(&user).Where("email = ?", email).Updates(&user).RowsAffected == 0 { db.Create(&user) }
This works for gorm v1.9.15 and go 1.13