prisma-client-php 4.1.5 → 4.1.7

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.
@@ -26,18 +26,18 @@ import { PrismaClient } from "@prisma/client";
26
26
 
27
27
  // --- OPTION C: MYSQL / MARIADB ------------------------------
28
28
  // import { PrismaMariaDb } from "@prisma/adapter-mariadb";
29
- // import { createPool } from "mariadb";
29
+ // import { PoolConfig } from "mariadb";
30
30
 
31
31
  // const connectionUrl = new URL(process.env.DATABASE_URL!);
32
- // const pool = createPool({
32
+ // const poolConfig: PoolConfig = {
33
33
  // host: connectionUrl.hostname,
34
34
  // port: Number(connectionUrl.port) || 3306,
35
35
  // user: connectionUrl.username,
36
36
  // password: connectionUrl.password,
37
37
  // database: connectionUrl.pathname.slice(1),
38
38
  // connectionLimit: 5,
39
- // });
40
- // const adapter = new PrismaMariaDb(pool);
39
+ // };
40
+ // const adapter = new PrismaMariaDb(poolConfig);
41
41
  // const prisma = new PrismaClient({ adapter });
42
42
  // ------------------------------------------------------------
43
43
 
@@ -1637,29 +1637,53 @@ final class PPHPUtility
1637
1637
  }
1638
1638
 
1639
1639
  if (empty($relatedKeys['relationFromFields']) && empty($relatedKeys['relationToFields'])) {
1640
- $implicitModelInfo = self::compareStringsAlphabetically($relatedField['type'], get_class($relatedInstance));
1641
- $searchColumn = ($relatedField['type'] === $implicitModelInfo['A']) ? 'B' : 'A';
1642
-
1643
- $idField = null;
1644
- foreach ($record as $key => $value) {
1645
- if ($key === 'id' || str_ends_with($key, 'Id')) {
1646
- $idField = $key;
1647
- break;
1640
+ if ($relatedField['type'] === $relatedInstance->_modelName) {
1641
+ $relationName = $relatedField['relationName'] ?? null;
1642
+
1643
+ foreach ($relatedInstance->_fields as $fieldName => $fieldMeta) {
1644
+ if (($fieldMeta['relationName'] ?? null) === $relationName
1645
+ && !empty($relatedInstance->_fieldsRelatedWithKeys[$fieldName]['relationFromFields'])
1646
+ ) {
1647
+
1648
+ $oppositeKeys = $relatedInstance->_fieldsRelatedWithKeys[$fieldName];
1649
+ $relatedKeys = [
1650
+ 'relationFromFields' => $oppositeKeys['relationFromFields'],
1651
+ 'relationToFields' => $oppositeKeys['relationToFields']
1652
+ ];
1653
+ break;
1654
+ }
1648
1655
  }
1649
- }
1650
1656
 
1651
- if (!$idField || !isset($record[$idField])) {
1652
- return 0;
1653
- }
1657
+ if (empty($relatedKeys['relationFromFields'])) {
1658
+ return 0;
1659
+ }
1660
+ } else {
1661
+ $relatedClassName = $relatedInstance->_modelName ?? basename(str_replace('\\', '/', get_class($relatedInstance)));
1654
1662
 
1655
- $tableName = self::quoteColumnName($dbType, $implicitModelInfo['Name']);
1656
- $searchColumnQuoted = self::quoteColumnName($dbType, $searchColumn);
1663
+ $implicitModelInfo = self::compareStringsAlphabetically($relatedField['type'], $relatedClassName);
1664
+ $searchColumn = ($relatedField['type'] === $implicitModelInfo['A']) ? 'B' : 'A';
1657
1665
 
1658
- $sql = "SELECT COUNT(*) FROM $tableName WHERE $searchColumnQuoted = :id";
1659
- $stmt = $pdo->prepare($sql);
1660
- $stmt->execute(['id' => $record[$idField]]);
1666
+ $idField = null;
1667
+ foreach ($record as $key => $value) {
1668
+ if ($key === 'id' || str_ends_with($key, 'Id')) {
1669
+ $idField = $key;
1670
+ break;
1671
+ }
1672
+ }
1661
1673
 
1662
- return (int) $stmt->fetchColumn();
1674
+ if (!$idField || !isset($record[$idField])) {
1675
+ return 0;
1676
+ }
1677
+
1678
+ $tableName = self::quoteColumnName($dbType, $implicitModelInfo['Name']);
1679
+ $searchColumnQuoted = self::quoteColumnName($dbType, $searchColumn);
1680
+
1681
+ $sql = "SELECT COUNT(*) FROM $tableName WHERE $searchColumnQuoted = :id";
1682
+ $stmt = $pdo->prepare($sql);
1683
+ $stmt->execute(['id' => $record[$idField]]);
1684
+
1685
+ return (int) $stmt->fetchColumn();
1686
+ }
1663
1687
  }
1664
1688
 
1665
1689
  return 0;
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": "4.1.5",
4
+ "version": "4.1.7",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {