on-internet
← Community

unsupported data type: &[] error on GORM field where custom Valuer returns nil?

Stack Overflow ·

I was trying to create a GORM model for a postgres database, containing a type with a custom Scanner and Valuer that converts a string slice to and from a string, to be saved as a single database column. If the slice is either empty or nil, I want the database column to also be nil (as opposed to an empty string). type MultiString []string func (s *MultiString) Scan(src interface{}) error { str, ok := src.(string) if !ok { return errors.New("failed to scan multistring field - source is not a string") } *s = strings.Split(str, ",") return nil } func (s MultiString) Value() (driver.Value, error)

Comments

Sign in or sign up to comment and upvote.

No comments yet.