fix(csv-loader): handle object foreign keys in reverse lookups
Update `csvToModule` to check if a foreign key value is an object containing the default primary key before converting it to a string. This ensures correct key mapping when references are resolved as objects rather than primitive IDs.
This commit is contained in:
@@ -1199,7 +1199,8 @@ export function csvToModule(
|
||||
reverseLookupInits.push(
|
||||
`const ${revLookupVar} = new Map();`,
|
||||
`for (const r of _raw) {`,
|
||||
` const k = String(r.${decl.foreignKey});`,
|
||||
` const kv = r.${decl.foreignKey};`,
|
||||
` const k = String(typeof kv === "object" && "${defaultPrimaryKey}" in kv ? kv.${defaultPrimaryKey} : kv);`,
|
||||
` if (!${revLookupVar}.has(k)) ${revLookupVar}.set(k, []);`,
|
||||
` ${revLookupVar}.get(k).push(r);`,
|
||||
`}`,
|
||||
@@ -1209,7 +1210,8 @@ export function csvToModule(
|
||||
reverseLookupInits.push(
|
||||
`const ${revLookupVar} = new Map();`,
|
||||
`for (const r of ${varName}()) {`,
|
||||
` const k = String(r.${decl.foreignKey});`,
|
||||
` const kv = r.${decl.foreignKey};`,
|
||||
` const k = String(typeof kv === "object" && "${defaultPrimaryKey}" in kv ? kv.${defaultPrimaryKey} : kv);`,
|
||||
` if (!${revLookupVar}.has(k)) ${revLookupVar}.set(k, []);`,
|
||||
` ${revLookupVar}.get(k).push(r);`,
|
||||
`}`,
|
||||
|
||||
Reference in New Issue
Block a user