{"record":{"id":"a267d10b41e91dd1","repo":"go-gorm/gorm","slug":"relation-s-not-found","errorCode":null,"errorMessage":"relation %s not found","messagePattern":"relation (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"generics.go","lineNumber":501,"sourceCode":"\t\treturn db.Preload(association, func(tx *DB) *DB {\n\t\t\tq := preloadBuilder{db: tx.getInstance()}\n\t\t\tif query != nil {\n\t\t\t\tif err := query(&q); err != nil {\n\t\t\t\t\tdb.AddError(err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\trelation, ok := db.Statement.Schema.Relationships.Relations[association]\n\t\t\tif !ok {\n\t\t\t\tif preloadFields := strings.Split(association, \".\"); len(preloadFields) > 1 {\n\t\t\t\t\trelationships := &db.Statement.Schema.Relationships\n\t\t\t\t\tfor _, field := range preloadFields {\n\t\t\t\t\t\tvar ok bool\n\t\t\t\t\t\trelation, ok = relationships.Relations[field]\n\t\t\t\t\t\tif ok {\n\t\t\t\t\t\t\trelationships = &relation.FieldSchema.Relationships\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdb.AddError(fmt.Errorf(\"relation %s not found\", association))\n\t\t\t\t\t\t\treturn nil\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tdb.AddError(fmt.Errorf(\"relation %s not found\", association))\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif q.limitPerRecord > 0 {\n\t\t\t\tif relation.JoinTable != nil {\n\t\t\t\t\ttx.AddError(fmt.Errorf(\"many2many relation %s don't support LimitPerRecord\", association))\n\t\t\t\t\treturn tx\n\t\t\t\t}\n\n\t\t\t\trefColumns := []clause.Column{}\n\t\t\t\tfor _, rel := range relation.References {\n\t\t\t\t\tif rel.OwnPrimaryKey {","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/generics.go#L483-L519","documentation":"Error \"relation %s not found\" thrown in go-gorm/gorm.","triggerScenarios":"Thrown at generics.go:501 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the relation name matches the struct field name exactly (case-sensitive).","Ensure the related field is a struct or slice of structs so GORM parses it as a relation.","Verify the model was migrated/parsed before the call so relationships are registered."],"exampleFix":"Check the relation name against the model schema before Association(): if _, ok := stmt.Schema.Relationships.Relations[name]; !ok { return }","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1d6ce99528060be18a42be09aca8d39efcb47f28","analyzedAt":"2026-08-15T13:01:23.433Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}