laravel - 我的 Octobercms 数据透视表获得了模型表在我尝试添加时应该获得的数据

标签 laravel pivot-table relationships octobercms

我有一个烦人的问题,使用最新的 OctoberCMS build (318),它试图将错误的数据保存到数据透视表而不是模型表。

我有一个模范企业和一个模范营业时间:

企业模式:

`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是带有 business_id 的数据透视表和 openinghours_id
和开放时间模型:
public $table = 'ekstremedia_emcityportal_openinghours';
public $belongsToMany = [
        'businesses' => ['Ekstremedia\EmCityportal\Models\Business',
        'table' => 'ekstremedia_emcityportal_businesses',
        'order' => 'created_at desc'       
  ]
];   

在业务 Controller field.yaml我已经这样做了,为企业增加营业时间:
    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

问题是,october 试图将开放时间保存到数据透视表而不是模型表。任何人都知道我该如何解决这个问题?我尝试了很多不同的选择。 .

这是我在后端得到的错误:
 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等,在 ekstremedia_emcityportal_openinghours ,定义于 Openinghours模型,不在 ekstremedia_emcityportal_ohb这是数据透视表......

最佳答案

嗨,我认为您的案例是一个复杂的关系场景,对于 10 月的 cms 作为为您处理此问题的工具,它是 relation behavior事实上,表单行为对于简单的关系就足够了,或者当你在创建它们之后链接时思考。

在这里,您试图同时创建一个保存。
有一个 pretty good ressource about it我认为了解关系行为就足够了。

但是营业时间是否属于多个业务?

关于laravel - 我的 Octobercms 数据透视表获得了模型表在我尝试添加时应该获得的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36393632/

相关文章:

r - 在 R 中一次旋转表多个变量

javascript - 在 js 中维护元素组之间关系的最佳实践

neo4j - 图数据库中的条件关系

php - Laravel 不可能在哪里查询

laravel - 在 xampp localhost 中创建通配符子域

php - Laravel sql if 语句

php - Symfony2 : Disconnect Associations on delete

php - $request->file 不断返回 tmp 路径

php - 不要在数据透视表中插入值 (Laravel 5.8)

PHP MySQL 数据透视表代码