prisma-client-php 0.0.24 → 0.0.25
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.
|
@@ -718,14 +718,18 @@ final class PPHPUtility
|
|
|
718
718
|
}
|
|
719
719
|
|
|
720
720
|
public static function processRelation(
|
|
721
|
-
|
|
721
|
+
array $relatedField,
|
|
722
722
|
array $fieldData,
|
|
723
723
|
array $relationFromFields,
|
|
724
724
|
array $relationToFields,
|
|
725
725
|
string $relatedClassName,
|
|
726
|
+
string $model,
|
|
726
727
|
PDO $pdo,
|
|
728
|
+
string $dbType,
|
|
729
|
+
string $lastInsertId = '',
|
|
727
730
|
bool $requestOption = true,
|
|
728
731
|
): array {
|
|
732
|
+
$fieldName = $relatedField['name'];
|
|
729
733
|
if (count($relationFromFields) !== count($relationToFields)) {
|
|
730
734
|
throw new Exception("Mismatch between 'relationFromFields' and 'relationToFields' for relation '$fieldName'.");
|
|
731
735
|
}
|
|
@@ -738,8 +742,38 @@ final class PPHPUtility
|
|
|
738
742
|
$relatedData = ['data' => $fieldData['create']];
|
|
739
743
|
$relatedResult = $relatedClass->create($relatedData);
|
|
740
744
|
} elseif (isset($fieldData['connect'])) {
|
|
741
|
-
$
|
|
742
|
-
|
|
745
|
+
if (empty($relationToFields) && empty($relationFromFields) && !empty($lastInsertId)) {
|
|
746
|
+
$relatedDataArray = $fieldData['connect'];
|
|
747
|
+
$relatedId = is_array($relatedDataArray) ? reset($relatedDataArray) : $relatedDataArray;
|
|
748
|
+
$implicitModelInfo = PPHPUtility::compareStringsAlphabetically($relatedField['type'], $model);
|
|
749
|
+
$searchColumn = ($relatedField['type'] === $implicitModelInfo['A']) ? 'B' : 'A';
|
|
750
|
+
$returnColumn = ($searchColumn === 'A') ? 'B' : 'A';
|
|
751
|
+
|
|
752
|
+
$searchColumnValue = '';
|
|
753
|
+
$returnColumnValue = '';
|
|
754
|
+
if ($implicitModelInfo['A'] === $model) {
|
|
755
|
+
$searchColumnValue = $lastInsertId;
|
|
756
|
+
$returnColumnValue = $relatedId;
|
|
757
|
+
} else {
|
|
758
|
+
$searchColumnValue = $relatedId;
|
|
759
|
+
$returnColumnValue = $lastInsertId;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
$tableName = self::quoteColumnName($dbType, $implicitModelInfo['Name']);
|
|
763
|
+
$searchColumn = self::quoteColumnName($dbType, $searchColumn);
|
|
764
|
+
$returnColumn = self::quoteColumnName($dbType, $returnColumn);
|
|
765
|
+
$sql = "INSERT IGNORE INTO $tableName ($searchColumn, $returnColumn) VALUES (?,?)";
|
|
766
|
+
$stmt = $pdo->prepare($sql);
|
|
767
|
+
$stmt->execute([$searchColumnValue, $returnColumnValue]);
|
|
768
|
+
|
|
769
|
+
$sqlSelect = "SELECT * FROM $tableName WHERE $searchColumn = ? AND $returnColumn = ?";
|
|
770
|
+
$stmtSelect = $pdo->prepare($sqlSelect);
|
|
771
|
+
$stmtSelect->execute([$searchColumnValue, $returnColumnValue]);
|
|
772
|
+
$relatedResult = $stmtSelect->fetch();
|
|
773
|
+
} else {
|
|
774
|
+
$relatedData = ['where' => $fieldData['connect']];
|
|
775
|
+
$relatedResult = $relatedClass->findUnique($relatedData);
|
|
776
|
+
}
|
|
743
777
|
} elseif (isset($fieldData['connectOrCreate'])) {
|
|
744
778
|
$relatedData = ['where' => $fieldData['connectOrCreate']['where']];
|
|
745
779
|
$relatedResult = $relatedClass->findUnique($relatedData);
|
|
@@ -844,7 +878,8 @@ final class PPHPUtility
|
|
|
844
878
|
array $includes,
|
|
845
879
|
array $fields,
|
|
846
880
|
array $fieldsRelatedWithKeys,
|
|
847
|
-
PDO $pdo
|
|
881
|
+
PDO $pdo,
|
|
882
|
+
string $dbType,
|
|
848
883
|
): array {
|
|
849
884
|
$isSingle = !isset($records[0]) || !is_array($records[0]);
|
|
850
885
|
if ($isSingle) {
|
|
@@ -1007,7 +1042,10 @@ final class PPHPUtility
|
|
|
1007
1042
|
|
|
1008
1043
|
$idValue = $singleRecord[$idField];
|
|
1009
1044
|
|
|
1010
|
-
$
|
|
1045
|
+
$tableName = PPHPUtility::quoteColumnName($dbType, $implicitModelInfo['Name']);
|
|
1046
|
+
$searchColumn = PPHPUtility::quoteColumnName($dbType, $searchColumn);
|
|
1047
|
+
$returnColumn = PPHPUtility::quoteColumnName($dbType, $returnColumn);
|
|
1048
|
+
$sql = "SELECT " . $returnColumn . " FROM " . $tableName . " WHERE " . $searchColumn . " = :id";
|
|
1011
1049
|
$stmt = $pdo->prepare($sql);
|
|
1012
1050
|
$stmt->execute(['id' => $idValue]);
|
|
1013
1051
|
$implicitRecords = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
package/package.json
CHANGED