Skip to content

Instantly share code, notes, and snippets.

@amy
Last active April 27, 2017 00:59
Show Gist options
  • Save amy/8e8e075eef98d377c44e5259303a72ea to your computer and use it in GitHub Desktop.
Save amy/8e8e075eef98d377c44e5259303a72ea to your computer and use it in GitHub Desktop.
Goal: map result of query onto foo.
Issue: Only one of the structs is in the array.
I'm using gorm as an ORM.
type Bar struct {
test1 string
test2 string
}
var foo []Bar
someQuery := "... IN (?) ..."
// BEFORE: baz := "1,2,3"
baz := int[]{1,2,3}
db.Raw(someQuery, baz).Find(&foo)
// Also tried replacing Find with Scan
fmt.Printf("%v", foo)
// RESULT: [{1,1}]
Result when I just run someQuery on its own in mysql:
test1 | test2
1 | 1
2 | 2
3 | 3
.
.
.
etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment