zeeshan.mehtab18836
zeeshan.mehtab18836

Hi,

I am developing a plugin in which a Course hasMany Schedule . I want to be able to add/edit/delete schedules inside the course edit screen in the backend. I have followed the guidelines provided in http://octobercms.com/docs/backend/relations In Course Model: public $hasMany = [ 'schedules' => ['Echo1\Training\Models\Schedule', 'table' => 'echo1_training_schedules', 'order' => 'id'] ]; In Courses controller I have: public $implement = [ 'Backend.Behaviors.FormController', 'Backend.Behaviors.ListController', 'Backend.Behaviors.RelationController', ];

public $relationConfig = 'config_relation.yaml'; config_relation.yaml file for Courses controller: schedules: label: Course Schedule view: list: ~/plugins/echo1/training/models/schedule/columns.yaml toolbarButtons: create|delete manage: form: ~/plugins/echo1/training/models/schedule/fields.yaml recordsPerPage: 10

I have <?= $this->relationRender('schedules') ?> In course update.htm

When I update a Course I can see table for list of Schedules. When I click Add Schedule a popup form appears with timings input text field but when I save it throws me an error: Mass assignment failed for Model attribute 'Timings'

In the schedules table I have id, timings, course_id and timestamps. I have no validation rules inside Schedule Model.

Please help me if you have any idea how to resolve this error.

Thanks a lot.

zeeshan.mehtab18836
zeeshan.mehtab18836

Anyone with similar issue?

zeeshan.mehtab18836
zeeshan.mehtab18836

The back-end Relation feature for Many to Many relations is broken. I could not find any solution but I got enough evidence that this feature is broken in October and hopefully it will be resolved. Other relations are working fine like a charm. I really love the way relations work in back-end. Thank to the October Team.

omdreamreg6295
omdreamreg6295

I had the same problem.

Add to shedule model:

     /**
     * @var array Fillable fields
     */
    protected $fillable = [
        'Timings'
    ];

PS: for code use pre tag

Last updated

zeeshan.mehtab18836
zeeshan.mehtab18836

Thanks. That worked.

Tschallacka
Tschallacka

I had a similar issue when using a subform defined via config_relation.yaml

When trying to create a new one I got the error Mass assignment failed for Model attribute 'active'

By putting the field names that were not the "key" into the fillable array it became saveable. Take note to put relation field names as the relation field name in the fillable array in the model

Asinox
Asinox

Thank, worked for me too!

Vijay Wilson
Vijay Wilson

Thanks. It works as expected

Last updated

spinkalher
spinkalher

omdreamreg6295 said:

I had the same problem.

Add to shedule model:

    /**
    * @var array Fillable fields
    */
   protected $fillable = [
       'Timings'
   ];

PS: for code use pre tag

Thanks It works

1-9 of 9