Skip to content
Discussion options

You must be logged in to vote

hey so i looked into this and its actually a bug in how the generics api handles HasMany joins during scanning.

basically whats happening is:

  1. clause.Has("Tokens") makes gorm add column aliases like Tokens__id, Tokens__token etc to the SELECT
  2. in scan.go, when it sees those aliased columns, it resolves rel.Field for the Tokens field on your User struct
  3. then in scanIntoStruct, it calls ReflectValueOf on that field to try and set the scanned values
  4. but Tokens is []Token (a slice), and ReflectValueOf at schema/field.go:511 does v.Field(fieldIndex) which only works on structs, not slices. so it panics

the traditional api doesnt have this problem because when u pass a raw join string like "INN…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@fakeowl1
Comment options

@timsavage
Comment options

Answer selected by fakeowl1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants