hi, just create a simple model that uses []string and it'll crash with something like this https://gist.github.com/AvianFlu/4688697c15b3587623a2
ie:
type User struct {
Id int64
Name string
Emails []string
}
hi gorm doesn't support []string because database dialect that you are using don't know how to store it to database.
So maybe you need to write a Scanner for slice.
@jinzhu, would you be willing to show an example of how to make something like the above example work? I'm working on creating an API, and it would be much more succinct to have something like:
{
"name" : "Test",
"products" : [ "product1", "product2" ]
}
As opposed to the current way of doing it:
{
"name" : "Test",
"products" : [
{ "value" : "product1" },
{ "value" : "product2" }
}
Any help would be appreciated!
I meet this issue too.
Yea, I'm running into this issue as well, and I have seen a bunch of old issues about this as well.
@jinzhu you've mentioned writing a Scanner or a Valuer for this situation. Do you mind expounding on what you are referring to? Maybe a link to an example.
Ok, I've found the interface definition here: https://golang.org/pkg/database/sql/#Scanner. Hopefully this will do the trick.
Most helpful comment
@jinzhu, would you be willing to show an example of how to make something like the above example work? I'm working on creating an API, and it would be much more succinct to have something like:
As opposed to the current way of doing it:
Any help would be appreciated!