Skip to content

Commit a1b02a9

Browse files
committed
fix for mass insert
1 parent 11057ae commit a1b02a9

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/Package/System/events/collection.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
//for each row
9696
foreach ($data['rows'] as $i => $row) {
9797
//prepare the data
98+
//NOTE: This removes the potential relational IDs
99+
// (we need to reinsert these later)
98100
$data['rows'][$i] = $schema->prepare($row, true);
99101
//dont allow to insert the primary id
100102
unset($data['rows'][$i][$primary]);
@@ -135,6 +137,12 @@
135137
foreach ($schema->getRelations() as $table => $relation) {
136138
//set the 2nd primary
137139
$primary2 = $relation['primary2'];
140+
//look in stage for this ID because prepare() would have removed this
141+
$id2 = $request->getStage('rows', $i, $primary2);
142+
//reinsert the relative id
143+
if (is_numeric($id2)) {
144+
$row[$primary2] = $id2;
145+
}
138146
//if id is invalid
139147
if (!isset($row[$primary2]) || !is_numeric($row[$primary2])) {
140148
//skip
@@ -155,6 +163,12 @@
155163
foreach ($schema->getReverseRelations() as $table => $relation) {
156164
//set the 2nd primary
157165
$primary2 = $relation['primary2'];
166+
//look in stage for this ID because prepare() would have removed this
167+
$id2 = $request->getStage('rows', $i, $primary2);
168+
//reinsert the relative id
169+
if (is_numeric($id2)) {
170+
$row[$primary2] = $id2;
171+
}
158172
//if id is invalid
159173
if (!isset($row[$primary2]) || !is_numeric($row[$primary2])) {
160174
//skip

0 commit comments

Comments
 (0)