Skip to content

Commit

Permalink
Update RelationTrait.php
Browse files Browse the repository at this point in the history
  • Loading branch information
mootensai committed Feb 26, 2016
1 parent d3062f5 commit 0e61e70
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions RelationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,16 @@ public function saveAll()
$error = true;
}
}else{
foreach ($rel['link'] as $k => $v) {
$condition[] = $k . " = " . $this->$v;
}
try {
$relModel->deleteAll(implode(" AND ", $condition));
} catch (\yii\db\IntegrityException $exc) {
$this->addError($rel['name'], "Data can't be deleted because it's still used by another data.");
$error = true;
if($rel['ismultiple']){
foreach ($rel['link'] as $k => $v) {
$condition[] = $k . " = " . $this->$v;
}
try {
$relModel->deleteAll(implode(" AND ", $condition));
} catch (\yii\db\IntegrityException $exc) {
$this->addError($rel['name'], "Data can't be deleted because it's still used by another data.");
$error = true;
}
}
}
}
Expand Down

0 comments on commit 0e61e70

Please sign in to comment.