This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

TerjeN
TerjeN

Heya, I have an annoying problem. I have a model Businesses, and a model Openinghours.

Model for Businesses:

`public $table = 'ekstremedia_emcityportal_businesses';`
`public $belongsToMany = [
    'openinghours' => [
            'Ekstremedia\EmCityportal\Models\Openinghours',
            'table' => 'ekstremedia_emcityportal_ohb',
            'order' => 'week_day',
            'week_day' => 'week_day',
            'name' => 'week_day',
    ]           
];`    

ekstremedia_emcityportal_ohb is the pivot table with business_id and openinghours_id

And model for Openinghours:

public $table = 'ekstremedia_emcityportal_openinghours';
public $belongsToMany = [
        'businesses' => ['Ekstremedia\EmCityportal\Models\Business',
        'table' => 'ekstremedia_emcityportal_businesses',
        'order' => 'created_at desc'       
  ]
];   

In the Business controllers field.yaml i have done this, to add opening hours to a business:

    openinghours:
        type: repeater
        label: 'Åpningstider'
        tab: 'Åpningstider'
        form:
            fields:
                week_day:
                    label: Dag
                    oc.commentPosition: ''
                    options:
                        1: Måndag
                        2: Tysdag
                        3: Onsdag
                        4: Torsdag
                        5: Fredag
                        6: Laurdag
                        7: Sundag
                    span: left
                    type: dropdown
                open_hour:
                    label: Date added
                    type: datepicker
                    mode: time
                close_hour:
                    mode: time
                    label: Date added
                    type: datepicker

The problem is, october is trying to save the opening hours to the pivot table and not the model table. Anyone have an idea how i can fix that? Ive tried alot of different options. .

This is the error i get on the backend:

 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'close_hour' in 'field list' (SQL: insert into 'ekstremedia_emcityportal_ohb' ('business_id', 'close_hour', 'open_hour', 'openinghours_id', 'week_day')...

close_hour, open_hour, openinghours_id, week_day etc, is in ekstremedia_emcityportal_openinghours , defined in Openinghours model, not in ekstremedia_emcityportal_ohb wich is the pivot table...

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.