Skip to content

Commit 8d4f9db

Browse files
authored
Merge pull request #63 from Spoje-NET/62-multilple-releations-parsing-problem
Update RO.php
2 parents ab325b9 + 1b88578 commit 8d4f9db

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/AbraFlexi/RO.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,14 @@ public function fixResponseTypes(array $response)
10451045
}
10461046

10471047
/**
1048-
* Fix AbraFlexi record field types.
1048+
* Converts the fields of an AbraFlexi record array to appropriate native PHP types based on column metadata.
10491049
*
1050-
* @param string $evidence force other than current
1050+
* Fields are cast or transformed according to their defined types, including booleans, numbers, strings, dates, and relations. Relation fields are converted to `Relation` objects, supporting both single and multiple values. Unknown field types result in an exception.
10511051
*
1052-
* @throws \Ease\Exception
1053-
*
1054-
* @return array with items typed
1052+
* @param array $record The record data to typecast.
1053+
* @param string|null $evidence Optional evidence name to override the current one.
1054+
* @return array The record with fields converted to native types or objects.
1055+
* @throws \Ease\Exception If an unknown field type is encountered.
10551056
*/
10561057
public function fixRecordTypes(array $record, $evidence = null)
10571058
{
@@ -1070,12 +1071,24 @@ public function fixRecordTypes(array $record, $evidence = null)
10701071

10711072
break;
10721073
case 'relation':
1073-
$record[$column] = new Relation(
1074-
\is_array($value) ? $value[0] : $value,
1075-
\array_key_exists('fkEvidencePath', $columnInfo) && null !== $columnInfo['fkEvidencePath'] ? $columnInfo['fkEvidencePath'] : $column,
1076-
\array_key_exists($column.'@ref', $record) ? $record[$column.'@ref'] : null,
1077-
\array_key_exists($column.'@showAs', $record) ? $record[$column.'@showAs'] : null,
1078-
);
1074+
if (\is_array($record[$column])) {
1075+
foreach ($record[$column] as $pos => $value) {
1076+
$record[$column][$pos] = new Relation(
1077+
\is_array($value) ? $value[0] : $value,
1078+
\array_key_exists('fkEvidencePath', $columnInfo) && null !== $columnInfo['fkEvidencePath'] ? $columnInfo['fkEvidencePath'] : $column,
1079+
\array_key_exists($column.'@ref', $record) ? $record[$column.'@ref'] : null,
1080+
\array_key_exists($column.'@showAs', $record) ? $record[$column.'@showAs'] : null,
1081+
);
1082+
}
1083+
} else {
1084+
$record[$column] = new Relation(
1085+
\is_array($value) ? $value[0] : $value,
1086+
\array_key_exists('fkEvidencePath', $columnInfo) && null !== $columnInfo['fkEvidencePath'] ? $columnInfo['fkEvidencePath'] : $column,
1087+
\array_key_exists($column.'@ref', $record) ? $record[$column.'@ref'] : null,
1088+
\array_key_exists($column.'@showAs', $record) ? $record[$column.'@showAs'] : null,
1089+
);
1090+
}
1091+
10791092
unset($record[$column.'@ref'], $record[$column.'@showAs']);
10801093

10811094
break;

0 commit comments

Comments
 (0)