troelskn / laravel-fillable-relations

Provides HasFillableRelations trait to Eloquent models
63 stars 23 forks source link

Should it work for multiple levels? #5

Closed jamesratcliffe closed 6 years ago

jamesratcliffe commented 6 years ago

I have a 3-level hierarchy using hasMany. Models are in this gist.

This gives an error:

$tool = new Tool([
    'name' => 'vacuum',
    'fields' => [
        [
            'name' => 'full',
            'choices' => [
                [
                    'name' => 'on'
                ]
            ]
        ]
    ]
]);
SQLSTATE[HY000]: General error: 1364 Field 'tool_id' doesn't have a default value (SQL: insert into `tool_fields` (`name`, `updated_at`, `created_at`) values (full, 2017-12-01 18:00:40, 2017-12-01 18:00:40))

If I leave out the choice, it's fine. The field is inserted with the correct tool_id.

$tool = new Tool([
    'name' => 'vacuum',
    'fields' => [
        [
            'name' => 'full'
        ]
    ]
]);
troelskn commented 6 years ago

Thanks for reporting this James.

Indeed, that should work and it doesn't. I've taken your code and created a unit test to demonstrate it: https://github.com/troelskn/laravel-fillable-relations/tree/bug/three-level-fill

troelskn commented 6 years ago

Fixed in #6