prisma-client-php 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1045,22 +1045,62 @@ final class PPHPUtility
|
|
|
1045
1045
|
$parentId = $operations[0][$childFkFields[0]]
|
|
1046
1046
|
?? throw new Exception("Missing parent id in 'set' for '{$relatedFieldName}'.");
|
|
1047
1047
|
|
|
1048
|
-
$
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1048
|
+
$keepIds = [];
|
|
1049
|
+
foreach ($operations as $opSet) {
|
|
1050
|
+
if (isset($opSet[$relatedClass->_primaryKey])) {
|
|
1051
|
+
$keepIds[] = $opSet[$relatedClass->_primaryKey];
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
$deleteWhere = [
|
|
1056
|
+
$childFkFields[0] => $parentId,
|
|
1057
|
+
];
|
|
1058
|
+
if ($keepIds) {
|
|
1059
|
+
$deleteWhere[$relatedClass->_primaryKey] = ['notIn' => $keepIds];
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
$relatedClass->deleteMany(['where' => $deleteWhere]);
|
|
1052
1063
|
|
|
1053
1064
|
$newIds = [];
|
|
1054
1065
|
foreach ($operations as $opSet) {
|
|
1055
|
-
$where
|
|
1056
|
-
$fkUpdate
|
|
1057
|
-
|
|
1058
|
-
$
|
|
1066
|
+
$where = array_diff_key($opSet, array_flip($childFkFields));
|
|
1067
|
+
$fkUpdate = array_fill_keys($childFkFields, $parentId);
|
|
1068
|
+
|
|
1069
|
+
$row = $relatedClass->upsert([
|
|
1070
|
+
'where' => $where,
|
|
1071
|
+
'update' => $fkUpdate,
|
|
1072
|
+
'create' => array_merge($where, $fkUpdate),
|
|
1073
|
+
]);
|
|
1074
|
+
|
|
1075
|
+
$newIds[] = $row->{$relatedClass->_primaryKey};
|
|
1059
1076
|
}
|
|
1060
1077
|
|
|
1061
1078
|
$relatedResult = $relatedClass->findMany([
|
|
1062
|
-
'where' => [
|
|
1079
|
+
'where' => [
|
|
1080
|
+
$relatedClass->_primaryKey => ['in' => $newIds],
|
|
1081
|
+
],
|
|
1063
1082
|
]);
|
|
1083
|
+
$relatedResult = (array)$relatedResult;
|
|
1084
|
+
|
|
1085
|
+
if (!$requestOption) {
|
|
1086
|
+
return $relatedResult;
|
|
1087
|
+
}
|
|
1088
|
+
if (!$relatedResult) {
|
|
1089
|
+
throw new Exception("Failed to process related record for '{$relatedFieldName}'.");
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
if ($modelRelatedFieldIsList) {
|
|
1093
|
+
return [];
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
$bindings = [];
|
|
1097
|
+
foreach ($modelRelatedFromFields as $i => $fromField) {
|
|
1098
|
+
$toField = $modelRelatedToFields[$i];
|
|
1099
|
+
if (!isset($relatedResult[$toField])) {
|
|
1100
|
+
throw new Exception("The field '{$toField}' is missing …");
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
return $bindings;
|
|
1064
1104
|
} elseif (empty($modelRelatedFromFields) && empty($modelRelatedToFields)) {
|
|
1065
1105
|
$newRelatedIds = [];
|
|
1066
1106
|
$primaryId = null;
|
package/package.json
CHANGED