{"record":{"id":"acce4ec576232d94","repo":"remix-run/remix","slug":"relation-key-mismatch-between-sourcetablename","errorCode":null,"errorMessage":"Relation key mismatch between \"{sourceTableName}\" ({sourceKey}) and \"{targetTableName}\" ({targetKey})","messagePattern":"Relation key mismatch between \"(.+?)\" \\((.+?)\\) and \"(.+?)\" \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/data-table/src/lib/table.ts","lineNumber":1184,"sourceCode":"\n  if (options === true) {\n    return { ...defaultTimestampConfig }\n  }\n\n  return {\n    createdAt: options.createdAt ?? defaultTimestampConfig.createdAt,\n    updatedAt: options.updatedAt ?? defaultTimestampConfig.updatedAt,\n  }\n}\n\nfunction assertKeyLengths(\n  sourceTableName: string,\n  targetTableName: string,\n  sourceKey: string[],\n  targetKey: string[],\n): void {\n  if (sourceKey.length !== targetKey.length) {\n    throw new Error(\n      'Relation key mismatch between \"' +\n        sourceTableName +\n        '\" (' +\n        sourceKey.join(', ') +\n        ') and \"' +\n        targetTableName +\n        '\" (' +\n        targetKey.join(', ') +\n        ')',\n    )\n  }\n}\n\ntype CreateRelationOptions<\n  source extends AnyTable,\n  target extends AnyTable,\n  cardinality extends RelationCardinality,\n> = {","sourceCodeStart":1166,"sourceCodeEnd":1202,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/data-table/src/lib/table.ts#L1166-L1202","documentation":"Relations match source and target columns pairwise; the number of key columns on each side must be equal. This error fires when e.g. the source key lists one column but the target key lists two, making the join unresolvable.","triggerScenarios":"belongsTo(..., { sourceKey: ['tenantId','id'], targetKey: ['id'] }) or similar asymmetric key arrays in a relation definition.","commonSituations":"Composite foreign keys where one side was updated but not the other; copy-pasting a single-column relation and adding a column to only one key list.","solutions":["Make sourceKey and targetKey arrays the same length, pairing each column correctly","For composite keys, list columns in matching order on both sides","Re-check which side needs multiple columns — usually both or neither"],"exampleFix":"// before\nbelongsTo(users, { sourceKey: ['tenantId','userId'], targetKey: ['id'] })\n// after\nbelongsTo(users, { sourceKey: ['tenantId','userId'], targetKey: ['tenantId','id'] })","handlingStrategy":"validation","validationCode":"if (sourceKey.length !== targetKey.length) throw new Error('relation key arity mismatch')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair composite key columns in the same order on both sides","Add a helper that asserts matching arity when defining relations"],"tags":["data-table","relations","join"],"backgroundTag":"invalid-relation-definition","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}