prisma-client-php 0.0.22 → 0.0.23

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.
@@ -236,15 +236,17 @@ final class PPHPUtility
236
236
  throw new Exception("The '$value' is indexed, waiting example: ['$value' => true]");
237
237
  }
238
238
 
239
- if (isset($value) && empty($value) || !is_bool($value)) {
240
- continue;
239
+ if (is_array($value) && isset($value['include'])) {
240
+ $includes[$key] = $value;
241
+ } elseif (is_bool($value)) {
242
+ $includes[$key] = $value;
243
+ } elseif (!is_array($value)) {
244
+ throw new Exception("Invalid include format for '$key'. Expecting an array or boolean.");
241
245
  }
242
246
 
243
247
  if (!array_key_exists($key, $fields)) {
244
248
  throw new Exception("The field '$key' does not exist in the $modelName model.");
245
249
  }
246
-
247
- $includes[$key] = $value;
248
250
  }
249
251
  }
250
252
  }
@@ -871,7 +873,7 @@ final class PPHPUtility
871
873
  foreach ($relatedFieldKeys['relationFromFields'] as $index => $fromField) {
872
874
  $toField = $relatedFieldKeys['relationToFields'][$index];
873
875
 
874
- if (!array_key_exists($toField, $singleRecord)) {
876
+ if (!array_key_exists($toField, $singleRecord) && !array_key_exists($fromField, $singleRecord)) {
875
877
  continue 2;
876
878
  }
877
879
 
@@ -951,7 +953,29 @@ final class PPHPUtility
951
953
  }
952
954
 
953
955
  if (empty($queryOptions)) {
954
- $relatedFieldResult = $relatedInstance->findMany();
956
+ $relatedFieldByRelationName = array_filter(
957
+ $fields,
958
+ fn($field) => isset($field['relationName'])
959
+ && $field['relationName'] === $relatedInstanceField['relationName']
960
+ && isset($relatedInstanceField['name'])
961
+ && $relatedInstanceField['name'] !== $field['name']
962
+ );
963
+
964
+ $whereConditions = [];
965
+ if (!empty($relatedFieldByRelationName)) {
966
+ $firstRelatedField = reset($relatedFieldByRelationName);
967
+ if (!empty($firstRelatedField['relationFromFields']) && isset($firstRelatedField['relationFromFields'][0])) {
968
+ $whereConditions[$firstRelatedField['relationFromFields'][0]] = $singleRecord[$firstRelatedField['relationToFields'][0]];
969
+ }
970
+ }
971
+
972
+ if (!empty($whereConditions)) {
973
+ $relatedFieldResult = $relatedInstance->findMany(
974
+ ['where' => $whereConditions]
975
+ );
976
+ } else {
977
+ $relatedFieldResult = $relatedInstance->findMany();
978
+ }
955
979
  } else {
956
980
  $relatedFieldResult = $relatedInstance->findMany($queryOptions);
957
981
  }
@@ -20,5 +20,5 @@ interface IModel
20
20
  // public function updateManyAndReturn(array $data);
21
21
  // public function update(array $data);
22
22
  // public function upsert(array $data);
23
- // public function count(array $criteria);
23
+ public function count(array $criteria);
24
24
  }
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": "0.0.22",
4
+ "version": "0.0.23",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {