Skip to content

Commit a61269f

Browse files
committed
Refines handling of 'relation' column for nested arrays
Updates logic to process 'relation' columns with nested arrays by introducing single-object mapping based on key fields. Improves data handling consistency and ensures accurate reference and display values for relation objects.
1 parent 491a726 commit a61269f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/AbraFlexi/RO.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,14 +1084,16 @@ public function fixRecordTypes(array $record, $evidence = null)
10841084
break;
10851085
case 'relation':
10861086
if (\is_array($record[$column])) {
1087-
foreach ($record[$column] as $pos => $value) {
1088-
$record[$column][$pos] = new Relation(
1089-
\is_array($value) ? $value['id'] : $value,
1090-
\array_key_exists('fkEvidencePath', $columnInfo) && null !== $columnInfo['fkEvidencePath'] ? $columnInfo['fkEvidencePath'] : $column,
1091-
\array_key_exists($column.'@ref', $record) ? $record[$column.'@ref'] : null,
1092-
\array_key_exists($column.'@showAs', $record) ? $record[$column.'@showAs'] : null,
1093-
);
1094-
}
1087+
$value = $record[$column][0];
1088+
1089+
$valueFields = array_keys($value);
1090+
$subject = next($valueFields);
1091+
$record[$column] = new Relation(
1092+
\is_array($value) ? ($value['kod'] ?: $value['id']) : $value,
1093+
\array_key_exists('fkEvidencePath', $columnInfo) && null !== $columnInfo['fkEvidencePath'] ? $columnInfo['fkEvidencePath'] : $column,
1094+
\array_key_exists($subject.'@ref', $value) ? $record[$subject.'@ref'] : $value['id'],
1095+
\array_key_exists($subject.'@showAs', $value) ? $value[$subject.'@showAs'] : null,
1096+
);
10951097
} else {
10961098
$record[$column] = new Relation(
10971099
\is_array($value) ? $value[0] : $value,

0 commit comments

Comments
 (0)