Skip to content

Commit a5878d0

Browse files
authored
Merge pull request #1814 from objectstack-ai/fix/seed-loader-id-resolution
2 parents fef38ec + 528c955 commit a5878d0

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

packages/objectql/src/seed-loader.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,25 @@ export class SeedLoaderService implements ISeedLoaderService {
448448
if (records && records.length > 0) {
449449
return String(records[0].id || records[0]._id);
450450
}
451+
// Fallback: the value may already be the target's internal id rather than
452+
// its natural key — a seed that wires a lookup to a real existing record
453+
// (e.g. a people field → the current user, whose id is not a UUID/ObjectId
454+
// so `looksLikeInternalId` did not short-circuit). Resolving by id lets a
455+
// valid id resolve instead of dangling null, with no risk of a false
456+
// natural-key match (an id either exists or it does not).
457+
if (targetField !== 'id') {
458+
const byId: Record<string, unknown> = { id: value };
459+
if (organizationId) byId.organization_id = organizationId;
460+
const idMatch = await this.engine.find(targetObject, {
461+
where: byId,
462+
fields: ['id'],
463+
limit: 1,
464+
context: { isSystem: true },
465+
} as any);
466+
if (idMatch && idMatch.length > 0) {
467+
return String(idMatch[0].id || idMatch[0]._id);
468+
}
469+
}
451470
} catch {
452471
// Target object may not exist yet
453472
}

0 commit comments

Comments
 (0)