prisma-client-php 2.0.1 → 2.0.2

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,30 @@ 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
+ $relatedResult = self::handleImplicitRelationInsert(
893
910
  $modelName,
894
911
  $modelRelatedFieldType,
895
912
  $dbType,
896
913
  $pdo,
897
- $modelFieldData[$modelClass->_primaryKey],
898
914
  $relatedFieldData[$relatedClass->_primaryKey],
915
+ $modelFieldData[$modelClass->_primaryKey],
899
916
  );
900
917
  } else {
901
918
  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.2",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {