Skip to content

Commit c1c1008

Browse files
committed
Update RelationTrait.php
1 parent 0655e73 commit c1c1008

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

RelationTrait.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function saveAll()
8484
$isNewRecord = $this->isNewRecord;
8585
try {
8686
if ($this->save()) {
87-
$error = 0;
87+
$error = false;
8888
if (!empty($this->relatedRecords)) {
8989
foreach ($this->relatedRecords as $name => $records) {
9090
if (!empty($records)) {
@@ -114,7 +114,7 @@ public function saveAll()
114114
$this->addError($name, "$relModelWords #$index : $errorMsg");
115115
}
116116
}
117-
$error = 1;
117+
$error = true;
118118
} else {
119119
//GET PK OF REL MODEL
120120
if ($isManyMany) {
@@ -149,6 +149,7 @@ public function saveAll()
149149
$relModel->deleteAll($compiledNotDeletedPK);
150150
} catch (\yii\db\IntegrityException $exc) {
151151
$this->addError($name, "Data can't be deleted because it's still used by another data.");
152+
$error = true;
152153
}
153154
} else {
154155
$notDeletedFK = implode(' AND ', $notDeletedFK);
@@ -159,6 +160,7 @@ public function saveAll()
159160

160161
} catch (\yii\db\IntegrityException $exc) {
161162
$this->addError($name, "Data can't be deleted because it's still used by another data.");
163+
$error = 1;
162164
}
163165
}
164166
}
@@ -207,6 +209,7 @@ public function saveAll()
207209

208210
if ($error) {
209211
$trans->rollback();
212+
$this->isNewRecord = $isNewRecord;
210213
return false;
211214
}
212215
$trans->commit();
@@ -216,6 +219,7 @@ public function saveAll()
216219
}
217220
} catch (Exception $exc) {
218221
$trans->rollBack();
222+
$this->isNewRecord = $isNewRecord;
219223
throw $exc;
220224
}
221225
}

0 commit comments

Comments
 (0)