October: File Upload forms does not work with Relation Manager and $attachOne

Created on 13 Jan 2017  路  3Comments  路  Source: octobercms/october

Expected behavior

When i upload file by relation manager, i expect that file will be uploaded to related model

Actual behavior

File is added to deferred_bindings table but not to model

Reproduce steps

main model has $hasOne binding to another model. Atother model has $attachOne relation to file.

October build

382

Suggested fix (modules/backend/behaviors/RelationController.php):

 public function onRelationManageUpdate()
    {
        $this->forceManageMode = 'form';
        $this->beforeAjax();
        $saveData = $this->manageWidget->getSaveData();

        if ($this->viewMode == 'multi') {
            $model = $this->relationModel->find($this->manageId);
            $modelsToSave = $this->prepareModelsToSave($model, $saveData);
            foreach ($modelsToSave as $modelToSave) {
                $modelToSave->save(null, $this->manageWidget->getSessionKey());
            }
        }
        elseif ($this->viewMode == 'single') {
            $this->viewWidget->setFormValues($saveData);
            $this->viewModel->save(null, $this->manageWidget->getSessionKey());
        }

        return ['#'.$this->relationGetId('view') => $this->relationRenderView()];
    }
Completed Bug

Most helpful comment

Fixed by #2610, thanks @lukaszbanas-extremecoding!

All 3 comments

@lukaszbanas-extremecoding Are you able to submit a PR to the test plugin for replication so that we can test your issue and your fix?

Fixed by #2610, thanks @lukaszbanas-extremecoding!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mittultechnobrave picture mittultechnobrave  路  3Comments

EbashuOnHolidays picture EbashuOnHolidays  路  3Comments

LukeTowers picture LukeTowers  路  3Comments

gergo85 picture gergo85  路  3Comments

sozonovalexey picture sozonovalexey  路  3Comments