File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments