{"record":{"id":"21c34ebe0ce8fb86","repo":"go-gorm/gorm","slug":"failed-to-find-relation-s","errorCode":null,"errorMessage":"failed to find relation: %s","messagePattern":"failed to find relation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gorm.go","lineNumber":505,"sourceCode":"\t\tmodelSchema, joinSchema *schema.Schema\n\t)\n\n\terr := stmt.Parse(model)\n\tif err != nil {\n\t\treturn err\n\t}\n\tmodelSchema = stmt.Schema\n\n\terr = stmt.Parse(joinTable)\n\tif err != nil {\n\t\treturn err\n\t}\n\tjoinSchema = stmt.Schema\n\n\trelation, ok := modelSchema.Relationships.Relations[field]\n\tisRelation := ok && relation.JoinTable != nil\n\tif !isRelation {\n\t\treturn fmt.Errorf(\"failed to find relation: %s\", field)\n\t}\n\n\tfor _, ref := range relation.References {\n\t\tf := joinSchema.LookUpField(ref.ForeignKey.DBName)\n\t\tif f == nil {\n\t\t\treturn fmt.Errorf(\"missing field %s for join table\", ref.ForeignKey.DBName)\n\t\t}\n\n\t\tf.DataType = ref.ForeignKey.DataType\n\t\tf.GORMDataType = ref.ForeignKey.GORMDataType\n\t\tif f.Size == 0 {\n\t\t\tf.Size = ref.ForeignKey.Size\n\t\t}\n\t\tref.ForeignKey = f\n\t}\n\n\tfor name, rel := range relation.JoinTable.Relationships.Relations {\n\t\tif _, ok := joinSchema.Relationships.Relations[name]; !ok {","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/gorm.go#L487-L523","documentation":"Error \"failed to find relation: %s\" thrown in go-gorm/gorm.","triggerScenarios":"Thrown at gorm.go:505 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the relation name passed to SetupJoinTable/Association exists on the model.","Ensure the schema was parsed (db.Model(&Model{})) before looking up the relation.","Check the relationship tags (foreignKey, references) so the relation is registered."],"exampleFix":"Verify the relation field name matches the struct field, e.g. db.Association(\"Orders\") where the field is Orders []Order.","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"}