go-rel / rel

:gem: Modern ORM for Golang - Testable, Extendable and Crafted Into a Clean and Elegant API
https://go-rel.github.io/
MIT License
762 stars 56 forks source link

Preload fails with go 1.21.0 #336

Closed nItroFreeZer closed 1 year ago

nItroFreeZer commented 1 year ago

Since go v1.21.0 Preload() fails with the following error on following code lines of rel. (With go v1.20.x all works fine.)

err = sql: Scan called without calling Next (closemuScanHold) https://github.com/go-rel/rel/blob/v0.39.0/cursor.go#L104 https://github.com/go-rel/rel/blob/v0.39.0/repository.go#L1068

Simplified example:

type ID uint
type Auth struct {
    Id             ID               `db:"id,primary"`
    AuthRoles      []AuthRoles      `ref:"id" fk:"auth_id"`
}
func (s Auth) Table() string {
    return "auth"
}

type AuthRoles struct {
    AuthId      ID        `db:"auth_id,primary"`
    RoleId      ID        `db:"role_id,primary"`
}
func (s AuthRoles) Table() string {
    return "auth_roles"
}

var a &Auth
err := repo.Find(context.Background(), a, where.Eq("xxx", xxx))
if err != nil {
   panic(err)
}

err = repo.Preload(context.Background(), a, "auth_roles")
if err != nil {
   panic(err)
}
Fs02 commented 1 year ago

thanks for reporting, I can reproduce this, seems there's change in the sql library and we need to adjust rel