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

Reflection issue when trying to Join relationships #7244

Open
fhendrikx opened this issue Oct 17, 2024 · 4 comments
Open

Reflection issue when trying to Join relationships #7244

fhendrikx opened this issue Oct 17, 2024 · 4 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@fhendrikx
Copy link

fhendrikx commented Oct 17, 2024

GORM Playground Link

go-gorm/playground#766

Description

I have a simple example here that shows when using First() I can preload the Pets and Pets.Toy relationship for a User, however, when trying to use the DB.Model and Rows() function to load multiple Users, this fails with the error:

panic: reflect: call of reflect.Value.Field on slice Value

goroutine 1 [running]:
reflect.Value.Field({0xafa4c0?, 0x4000612430?, 0xbe41c0?}, 0xaf6e00?)
	/usr/lib/go-1.19/src/reflect/value.go:1266 +0xec
gorm.io/gorm/schema.(*Field).setupValuerAndSetter.func5({0xbe41c0?, 0x4000612340?}, {0xafa4c0?, 0x4000612430?, 0x400053f1e8?})
	/home/ferry/go/pkg/mod/gorm.io/[email protected]/schema/field.go:502 +0xb8
gorm.io/gorm/schema.(*Field).setupValuerAndSetter.func9({0xd21130, 0x400013a040}, {0xafa4c0?, 0x4000612430?, 0x400053f278?}, {0xae4780?, 0x40001285e8?})
	/home/ferry/go/pkg/mod/gorm.io/[email protected]/schema/field.go:689 +0x2fc
gorm.io/gorm.(*DB).scanIntoStruct(0x40004e9410, {0xd227b8, 0x40004eaa80}, {0xbe41c0?, 0x4000612340?, 0x4549f4?}, {0x400017f500?, 0x17, 0x17}, {0x40004ce480, ...}, ...)
	/home/ferry/go/pkg/mod/gorm.io/[email protected]/scan.go:105 +0x434
gorm.io/gorm.Scan({0xd227b8, 0x40004eaa80}, 0x40004e9410, 0x1)
	/home/ferry/go/pkg/mod/gorm.io/[email protected]/scan.go:328 +0xbf4
gorm.io/gorm.(*DB).ScanRows(0x40004eaa80?, 0x400?, {0xaf4240?, 0x4000612340})
	/home/ferry/go/pkg/mod/gorm.io/[email protected]/finisher_api.go:586 +0x2e0
main.main()
	/home/ferry/dev/playground/main.go:63 +0x534
exit status 2

I apologies in advance if I have misunderstood something about GORM.

OS: Debian 12
GORM: 1.25.4
DB: Postgres 15

Thanks,
Ferry

@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Oct 17, 2024
@tboerger
Copy link

tboerger commented Oct 21, 2024

Looks like I'm running into the same issue... reflect: call of reflect.Value.Field on slice Value

db.WithContext(
	r.Context(),
).Model(
	&model.User{},
).InnerJoins(
	"Auths",
	db.Where(&model.UserAuth{
		Provider: "scim",
	}),
).Order(
	"username ASC",
).Find(
	&records,
)

@fhendrikx
Copy link
Author

Hi @tboerger Any thoughts on efficient work-arounds?

@tboerger
Copy link

I haven't found any working solution based on Gorm. Since nobody is really responding to this issue I have simply switched away from Form for my small project to Bun.

@fhendrikx
Copy link
Author

Thanks, I'm considering simply going back to using sqlx.

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

No branches or pull requests

3 participants