More efficient approach to locating a pivot record

This commit is contained in:
Samuel Georges 2015-02-28 19:53:41 +11:00
parent e48963b1e9
commit f2277b61dc
1 changed files with 3 additions and 5 deletions

View File

@ -1138,16 +1138,14 @@ class RelationController extends ControllerBehavior
* Existing record
*/
if ($this->manageId) {
$relations = $this->model->{$this->field};
$config->model = $relations->find($this->manageId);
$config->model = $this->relationModel->find($this->manageId);
$config->data = $this->relationObject->newPivotStatementForId($this->manageId)->first();
if (!$config->model) {
if (!$config->model || !$config->data) {
throw new ApplicationException(Lang::get('backend::lang.model.not_found', [
'class' => get_class($config->model), 'id' => $this->manageId
]));
}
$config->data = $config->model->pivot;
}
$widget = $this->makeWidget('Backend\Widgets\Form', $config);