Skip to content

Commit 887cdd2

Browse files
committed
[ORM] upsert() should ignore id or ai primay key #1317
1 parent 2dd27e0 commit 887cdd2

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

packages/orm/src/EntityMapper.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,12 +1041,13 @@ public function upsert(
10411041
$returningIdField = null;
10421042

10431043
if ($aiColumn = $metadata->getAutoIncrementColumn()) {
1044-
// Todo: MySQL no need to strip ai column, waiting pgsql test
1045-
// if (!in_array($aiColumn->getName(), $condFields, true)) {
1046-
// unset($data[$aiColumn->getName()]);
1047-
// }
1044+
$aiColumnName = $aiColumn->getName();
10481045

1049-
$returningIdField = $aiColumn->getName();
1046+
if (!in_array($aiColumnName, $condFields, true)) {
1047+
unset($data[$aiColumnName]);
1048+
}
1049+
1050+
$returningIdField = $aiColumnName;
10501051
}
10511052

10521053
if ($data !== []) {

packages/query/src/Bounded/BoundedHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public static function emulatePrepared(mixed $escaper, string $sql, array $bound
118118
}
119119
}
120120

121+
if ($v === null && $param['dataType'] === ParamType::NULL) {
122+
$v = 'NULL';
123+
}
124+
121125
$values[] = $v;
122126
}
123127

0 commit comments

Comments
 (0)