{"record":{"id":"205b0781a2eea90e","repo":"medusajs/medusa","slug":"duplicate-cross-module-join-target-table-join-t","errorCode":null,"errorMessage":"Duplicate cross-module join target table \"${join.target.table}\". Each join must target a unique table.","messagePattern":"Duplicate cross-module join target table \"(.+?)\"\\. Each join must target a unique table\\.","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/core/utils/src/dal/mikro-orm/cross-module-query/helpers.ts","lineNumber":163,"sourceCode":"    usedBaseAliases.set(baseAlias, usageCount + 1)\n    const alias =\n      usageCount === 0 ? baseAlias : `${baseAlias}_${usageCount + 1}`\n\n    return {\n      ...join,\n      alias,\n    }\n  })\n}\n\nfunction assertValidCrossModuleJoins(\n  crossModuleJoins: CrossModuleJoinSpec[]\n): void {\n  const targetTables = new Set<string>()\n\n  for (const join of crossModuleJoins) {\n    if (targetTables.has(join.target.table)) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `Duplicate cross-module join target table \"${join.target.table}\". Each join must target a unique table.`\n      )\n    }\n\n    targetTables.add(join.target.table)\n  }\n\n  for (const join of crossModuleJoins) {\n    if (!join.parent) {\n      continue\n    }\n\n    if (join.parent === join.target.table) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `Cross-module join for \"${join.target.table}\" cannot be its own parent.`\n      )","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/utils/src/dal/mikro-orm/cross-module-query/helpers.ts#L145-L181","documentation":"When composing cross-module joins in a single SQL query, each join must target a distinct table. Two join specs targeting the same table would produce ambiguous SQL, so Medusa validates and rejects duplicates with INVALID_DATA.","triggerScenarios":"Calling resolveCrossModuleJoins / building a query whose `joins` array contains two entries with the same `target.table`, e.g. joining product_variant twice in one filter set.","commonSituations":"Dynamically generated joins from user-selected filters that add the same relation twice, or copy-pasted join specs.","solutions":["De-duplicate join specs by target.table before submitting the query","If you need the same table twice, alias it via a subquery or restructure as separate queries","Validate user-supplied filter shapes against a fixed schema"],"exampleFix":"// before\njoins: [j1, j2] // both target \"variant\"\n// after\nconst joins = [...new Map(allJoins.map(j => [j.target.table, j])).values()]","handlingStrategy":"validation","validationCode":"const seen = new Set<string>()\nfor (const j of joins) { if (seen.has(j.target.table)) throw new Error(`duplicate join target ${j.target.table}`); seen.add(j.target.table) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["De-duplicate joins by target.table in your query builder","Constrain user-supplied filters to a fixed set of relations"],"tags":["query","joins","cross-module","validation"],"backgroundTag":"duplicate-join-in-query","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}