prisma-client-php 2.0.1 → 2.0.3

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.
@@ -889,13 +889,43 @@ final class PPHPUtility
889
889
  } elseif (empty($modelRelatedFromFields) && empty($modelRelatedToFields)) {
890
890
  $relatedFieldData = $op[$modelRelatedFieldType];
891
891
  $modelFieldData = $op[$modelName];
892
- $relatedResult = self::handleImplicitRelationInsert(
892
+
893
+ if (!isset($relatedFieldData[$relatedClass->_primaryKey])) {
894
+ $existing = $relatedClass->findUnique(['where' => $relatedFieldData]);
895
+ if (!$existing) {
896
+ throw new Exception("Cannot connect '{$relatedFieldName}': related record not found.");
897
+ }
898
+ $relatedFieldData[$relatedClass->_primaryKey] = $existing->{$relatedClass->_primaryKey};
899
+ }
900
+
901
+ if (!isset($modelFieldData[$modelClass->_primaryKey])) {
902
+ $existingParent = $modelClass->findUnique(['where' => $modelFieldData]);
903
+ if (!$existingParent) {
904
+ throw new Exception("Cannot connect '{$relatedFieldName}': parent record not found.");
905
+ }
906
+ $modelFieldData[$modelClass->_primaryKey] = $existingParent->{$modelClass->_primaryKey};
907
+ }
908
+
909
+ $relatedId = $relatedFieldData[$relatedClass->_primaryKey];
910
+ $modelId = $modelFieldData[$modelClass->_primaryKey];
911
+
912
+ $implicit = self::compareStringsAlphabetically($modelRelatedFieldType, $modelName);
913
+
914
+ if ($implicit['A'] === $modelName) {
915
+ $idA = $modelId;
916
+ $idB = $relatedId;
917
+ } else {
918
+ $idA = $relatedId;
919
+ $idB = $modelId;
920
+ }
921
+
922
+ $relatedResult = self::handleImplicitRelationInsert(
893
923
  $modelName,
894
924
  $modelRelatedFieldType,
895
925
  $dbType,
896
926
  $pdo,
897
- $modelFieldData[$modelClass->_primaryKey],
898
- $relatedFieldData[$relatedClass->_primaryKey],
927
+ $idA,
928
+ $idB
899
929
  );
900
930
  } else {
901
931
  if (!$modelRelatedFieldIsList && count($operations) > 1) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prisma-client-php",
3
3
  "description": "Prisma Client PHP is an auto-generated query builder that enables type-safe database access in PHP.",
4
- "version": "2.0.1",
4
+ "version": "2.0.3",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {