Index inherited compound identity restoration

This commit is contained in:
2026-10-25 23:17:59 +00:00
parent 75e209eb3b
commit f132cd6468
3 changed files with 102 additions and 11 deletions

View File

@@ -144,18 +144,24 @@ func preserveInheritanceIdentityFields(merged, child *document.Node, fields []st
if len(fields) == 0 || merged == nil || merged.Kind != document.Mapping || child == nil || child.Kind != document.Mapping {
return
}
identityFields := make(map[string]struct{}, len(fields))
for _, field := range fields {
for _, entry := range child.Mapping {
if entry.Key != field {
continue
}
for index := range merged.Mapping {
if merged.Mapping[index].Key == field {
merged.Mapping[index] = document.Entry{Key: field, Value: document.Clone(entry.Value)}
break
}
}
break
identityFields[field] = struct{}{}
}
positions := make(map[string]int, len(merged.Mapping))
for index, entry := range merged.Mapping {
if _, exists := positions[entry.Key]; !exists {
positions[entry.Key] = index
}
}
for _, entry := range child.Mapping {
if _, identity := identityFields[entry.Key]; !identity {
continue
}
delete(identityFields, entry.Key)
if index, exists := positions[entry.Key]; exists {
entry.Value = document.Clone(entry.Value)
merged.Mapping[index] = entry
}
}
}