{"record":{"id":"0fb748cff8fef8d4","repo":"flipped-aurora/gin-vue-admin","slug":"d-d-datasource-association-1-2","errorCode":null,"errorMessage":"模块 %d 字段 %d 的 dataSource.association 必须是 1 或 2","messagePattern":"模块 (.+?) 字段 (.+?) 的 dataSource\\.association 必须是 1 或 2","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/gva_execute.go","lineNumber":392,"sourceCode":"\t\t\t\tif !slices.Contains(validFieldTypes, field.FieldType) {\n\t\t\t\t\treturn fmt.Errorf(\"模块 %d 字段 %d 的 fieldType '%s' 不支持\", moduleIndex+1, i+1, field.FieldType)\n\t\t\t\t}\n\n\t\t\t\tif field.FieldSearchType != \"\" {\n\t\t\t\t\tvalidSearchTypes := []string{\"=\", \"!=\", \">\", \">=\", \"<\", \"<=\", \"LIKE\", \"BETWEEN\", \"NOT BETWEEN\", \"IN\", \"NOT IN\"}\n\t\t\t\t\tif !slices.Contains(validSearchTypes, field.FieldSearchType) {\n\t\t\t\t\t\treturn fmt.Errorf(\"模块 %d 字段 %d 的 fieldSearchType '%s' 不支持\", moduleIndex+1, i+1, field.FieldSearchType)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif field.DataSource != nil {\n\t\t\t\t\tassociationValue := field.DataSource.Association\n\t\t\t\t\tif associationValue == 2 && field.FieldType != \"array\" {\n\t\t\t\t\t\tlogger.WithCtx(ctx).Mod(\"mcp\").Info(fmt.Sprintf(\"module %d field %d association=2, force fieldType to array\", moduleIndex+1, i+1))\n\t\t\t\t\t\tmoduleInfo.Fields[i].FieldType = \"array\"\n\t\t\t\t\t}\n\t\t\t\t\tif associationValue != 1 && associationValue != 2 {\n\t\t\t\t\t\treturn fmt.Errorf(\"模块 %d 字段 %d 的 dataSource.association 必须是 1 或 2\", moduleIndex+1, i+1)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif !moduleInfo.GvaModel {\n\t\t\t\tprimaryKeyCount := 0\n\t\t\t\tfor _, field := range moduleInfo.Fields {\n\t\t\t\t\tif field.PrimaryKey {\n\t\t\t\t\t\tprimaryKeyCount++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif primaryKeyCount == 0 {\n\t\t\t\t\treturn fmt.Errorf(\"模块 %d：当 gvaModel=false 时，必须有一个字段的 primaryKey=true\", moduleIndex+1)\n\t\t\t\t}\n\t\t\t\tif primaryKeyCount > 1 {\n\t\t\t\t\treturn fmt.Errorf(\"模块 %d：当 gvaModel=false 时，只能有一个字段的 primaryKey=true\", moduleIndex+1)\n\t\t\t\t}\n\t\t\t} else {","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/gva_execute.go#L374-L410","documentation":"When a field has a dataSource block, its association value must be 1 (dictionary/direct options) or 2 (associated table). Any other integer (0, 3, -1) fails validation. Note association=2 is auto-corrected to force fieldType=array before this check.","triggerScenarios":"dataSource present in the plan field but association omitted (zero value 0) or set to an invalid number.","commonSituations":"JSON serialization dropping an unset association; LLM inventing association codes like 3 for 'many-to-many'; copy of a template where association was a different enum.","solutions":["Set dataSource.association to 1 (dictionary options) or 2 (table association)","Remove the dataSource block if the field has no data source","Remember association=2 requires/forces fieldType=array; set fieldType=array explicitly for table associations"],"exampleFix":"// before\n{\"fieldJson\":\"category\",\"fieldType\":\"int\",\"columnName\":\"category\",\"dataSource\":{\"association\":3}}\n// after\n{\"fieldJson\":\"category\",\"fieldType\":\"array\",\"columnName\":\"category\",\"dataSource\":{\"association\":2}}","handlingStrategy":"validation","validationCode":"if f.DataSource != nil && f.DataSource.Association != 1 && f.DataSource.Association != 2 {\n  return fmt.Errorf(\"association must be 1 or 2\")\n}","typeGuard":"func hasValidAssociation(f Field) bool {\n  return f.DataSource == nil || f.DataSource.Association == 1 || f.DataSource.Association == 2\n}","tryCatchPattern":null,"preventionTips":["Only emit dataSource blocks with explicit association 1 or 2","Use association=2 together with fieldType=array","Omit dataSource entirely for plain fields"],"tags":["validation","data-source","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}