I use gorm, and try to create transaction to mysql. I have a struct
type Game struct {
Images []string
}
game := Game{Images: []string{"1.png", "2.png"}}
db := Database()
tx := db.Begin()
if err := tx.Create(&game).Error; err != nil {
tx.Rollback()
return errors.New("Cannot add game")
}
tx.Commit()
But I get error (sql: converting argument $1 type: unsupported type []string, a slice of string). I understand, that mysql unsupported this type, but can I someway resolve this problem? I guess I can change type to json.rawMessage, but I think it's a wrong way.
I use dialect "github.com/jinzhu/gorm/dialects/mysql"
stringthat contains JSON encoded data, and marshal/unmarshal it as you write/read from the DB. However, the reason why this type isn't supported is because MySQL isn't supposed to be used like that. You should have an image table with a game ID in it and a path string or something like that instead.