Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strings slice causes goroutine to panic #51

Closed
yawnt opened this issue Jan 12, 2014 · 5 comments
Closed

strings slice causes goroutine to panic #51

yawnt opened this issue Jan 12, 2014 · 5 comments

Comments

@yawnt
Copy link

yawnt commented Jan 12, 2014

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
}
@jinzhu
Copy link
Member

jinzhu commented Jan 14, 2014

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 jinzhu closed this as completed Jan 14, 2014
@jordan-wright
Copy link

@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!

@xubing
Copy link

xubing commented Jul 27, 2016

I meet this issue too.

@thedodd
Copy link

thedodd commented Aug 4, 2016

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.

@thedodd
Copy link

thedodd commented Aug 4, 2016

Ok, I've found the interface definition here: https://golang.org/pkg/database/sql/#Scanner. Hopefully this will do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants