Add morphic relations to backend

This commit is contained in:
Aaron 2016-02-01 14:53:53 +10:00
parent af4f42e208
commit 0c4c39fddb
1 changed files with 8 additions and 2 deletions

View File

@ -1102,7 +1102,7 @@ class RelationController extends ControllerBehavior
if ($this->relationType == 'belongsToMany') {
$this->relationObject->detach($checkedIds);
}
elseif ($this->relationType == 'hasMany') {
elseif ($this->relationType == 'hasMany' || $this->relationType == 'morphMany') {
$relatedModel = $this->relationObject->getRelated();
foreach ($checkedIds as $relationId) {
if ($obj = $relatedModel->find($relationId)) {
@ -1121,7 +1121,7 @@ class RelationController extends ControllerBehavior
$this->relationObject->dissociate();
$this->relationObject->getParent()->save();
}
elseif ($this->relationType == 'hasOne') {
elseif ($this->relationType == 'hasOne' || $this->relationType == 'morphOne') {
if ($obj = $this->relationModel->find($recordId)) {
$this->relationObject->remove($obj);
}
@ -1295,10 +1295,12 @@ class RelationController extends ControllerBehavior
switch ($this->relationType) {
case 'hasMany':
case 'morphMany':
case 'belongsToMany':
return ['create', 'add', 'delete', 'remove'];
case 'hasOne':
case 'morphOne':
case 'belongsTo':
return ['create', 'update', 'link', 'delete', 'unlink'];
}
@ -1316,10 +1318,12 @@ class RelationController extends ControllerBehavior
switch ($this->relationType) {
case 'hasMany':
case 'morphMany':
case 'belongsToMany':
return 'multi';
case 'hasOne':
case 'morphOne':
case 'belongsTo':
return 'single';
}
@ -1358,7 +1362,9 @@ class RelationController extends ControllerBehavior
else return 'list';
case 'hasOne':
case 'morphOne':
case 'hasMany':
case 'morphMany':
if ($this->eventTarget == 'button-add') return 'list';
else return 'form';
}