1

I extends model Lovata\Buddies\User adding vendor relation. From backend form, I can create a new Vendor model and field commission is added fine. But if I update field value, the process show all fine, but the record is never updated in db. There is no error or exception.

enter image description here

User::extend(
    function ($obModel) {
        /** @var User $obModel */
        $obModel->hasOne['vendor'] = [Vendor::class];
    }
);

Vendor model has BelongsTo relation to User model

    public $belongsTo = [
        'user' => [User::class]
    ];

Users controller relation config

vendor:
    label: 'planetadeleste.vendorsshopaholic::lang.label.name'
    manage:
        form: $/planetadeleste/vendorsshopaholic/models/vendor/fields.yaml
        list: $/planetadeleste/vendorsshopaholic/models/vendor/columns.yaml
    view:
        form: $/planetadeleste/vendorsshopaholic/models/vendor/fields.yaml
        toolbarButtons: update|delete

Vendor fields

fields:
    commission:
        label: 'planetadeleste.vendorsshopaholic::lang.label.commission'
        span: left
alvaro.canepa
  • 562
  • 3
  • 13

2 Answers2

0

You need to add a user_id field to your Vendor DB table.

ref. https://octobercms.com/docs/database/relations#one-to-one

  • Thanks for answer. Yes, I have it. ```sql `user_id` int(10) unsigned NOT NULL `commission` decimal(5,2) DEFAULT NULL ``` – alvaro.canepa Sep 09 '20 at 15:46
0

Its bug in october core:
Just change line 1160 in modules\backend\behaviors\RelationController.php

Line 1160:

$this->viewModel = $this->manageWidget->model;

to this:

// Ensure that the view widget model is the same instance as the manage widget model
// since they will technically be different object instances in this context as
// $viewWidget->model is populated by $this->relationModel->getResults() and
// $manageWidget->model is populated by $this->relationModel->find($manageId);
$this->viewModel = $this->viewWidget->model = $this->manageWidget->model;
petkopalko
  • 600
  • 7
  • 18