Skip to content

Commit fa03ae6

Browse files
committed
fix for linking the wrong primary id in relation tables during mass insert event
1 parent 7cbfc6a commit fa03ae6

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

src/Package/System/events/collection.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,13 @@
116116
return;
117117
}
118118

119-
//get the last id
120-
$lastId = $response->getResults();
119+
//NOTE: in a mass insert, the last id is actually the first id
120+
$firstId = $response->getResults();
121121

122122
foreach ($data['rows'] as $i => $row) {
123123
//re insert the id into the rows
124-
//ex. 10 is the last id and there are 3 rows
125-
// 1st = 10 - (3 - (0 + 1)) = 8
126-
// 2nd = 10 - (3 - (1 + 1)) = 9
127-
// 3rd = 10 - (3 - (2 + 1)) = 10
128124
if (!isset($data['rows'][$i][$primary])) {
129-
$data['rows'][$i][$primary] = $lastId - (count($data['rows']) - ($i + 1));
125+
$data['rows'][$i][$primary] = $firstId + $i;
130126
}
131127

132128
$row[$primary] = $data['rows'][$i][$primary];

0 commit comments

Comments
 (0)