Refresh Relation Manager on Unlink and Delete (#4741)
Credit to @DanHarrin. Fixes #3470 and #4718. Replaces #3476.
This commit is contained in:
parent
a53cc52752
commit
3fc7f6aa76
|
|
@ -1187,6 +1187,9 @@ class RelationController extends ControllerBehavior
|
||||||
$relatedModel->delete();
|
$relatedModel->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reinitialise the form with a blank model
|
||||||
|
$this->initRelation($this->model);
|
||||||
|
|
||||||
$this->viewWidget->setFormValues([]);
|
$this->viewWidget->setFormValues([]);
|
||||||
$this->viewModel = $this->relationModel;
|
$this->viewModel = $this->relationModel;
|
||||||
}
|
}
|
||||||
|
|
@ -1281,6 +1284,12 @@ class RelationController extends ControllerBehavior
|
||||||
if ($this->relationType == 'belongsTo') {
|
if ($this->relationType == 'belongsTo') {
|
||||||
$this->relationObject->dissociate();
|
$this->relationObject->dissociate();
|
||||||
$this->relationObject->getParent()->save();
|
$this->relationObject->getParent()->save();
|
||||||
|
|
||||||
|
// If the relation manager isn't using deferred binding, reinitialise the form with a blank model
|
||||||
|
if (is_null($sessionKey)) {
|
||||||
|
$this->model->refresh();
|
||||||
|
$this->initRelation($this->model);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif ($this->relationType == 'hasOne' || $this->relationType == 'morphOne') {
|
elseif ($this->relationType == 'hasOne' || $this->relationType == 'morphOne') {
|
||||||
if ($obj = $relatedModel->find($recordId)) {
|
if ($obj = $relatedModel->find($recordId)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue