October CMS resources and help articles

Simple and to the point. Optimized by the community.

How to save belongsTo relation in one form without using relation form widget on create

1
by xyz.qtc, last modified on February 13th, 2024
    public function formExtendModel($model)
    {

         if ($this->action == 'create') {
             $model->address = new \Company\Plugin\Models\Address();
         }

         return $model;
    }

Define your fields in fields.yaml as

fields:
    address[streetname]:
                        label: Name
            type: text
    address[housenumber]:
                        label: House Number
            type: text
   address[zip]:
                        label: Zip
            type: text

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?