yassilah / laravel-nova-nested-form

This package allows you to include your nested relationships' forms into a parent form.
240 stars 96 forks source link

Exception: Column 'id' in field list is ambiguous #59

Open 4n70w4 opened 5 years ago

4n70w4 commented 5 years ago
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous (SQL: select `id` from `contacts` inner join `contactables` on `contacts`.`id` = `contactables`.`contact_id` where `contactables`.`contactable_id` = 96 and `contactables`.`contactable_type` = App\Organization and `id` not in (116))
select `id` from `contacts` inner join `contactables` on `contacts`.`id` = `contactables`.`contact_id` where `contactables`.`contactable_id` = ? and `contactables`.`contactable_type` = ? and `id` not in (?)
    "trace": [
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
            "line": 624,
            "function": "runQueryCallback",
            "class": "Illuminate\\Database\\Connection",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
            "line": 333,
            "function": "run",
            "class": "Illuminate\\Database\\Connection",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php",
            "line": 2124,
            "function": "select",
            "class": "Illuminate\\Database\\Connection",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php",
            "line": 2318,
            "function": "runSelect",
            "class": "Illuminate\\Database\\Query\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php",
            "line": 2598,
            "function": "Illuminate\\Database\\Query\\{closure}",
            "class": "Illuminate\\Database\\Query\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php",
            "line": 2320,
            "function": "onceWithColumns",
            "class": "Illuminate\\Database\\Query\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php",
            "line": 717,
            "function": "pluck",
            "class": "Illuminate\\Database\\Query\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php",
            "line": 23,
            "function": "pluck",
            "class": "Illuminate\\Database\\Eloquent\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Relation.php",
            "line": 386,
            "function": "forwardCallTo",
            "class": "Illuminate\\Database\\Eloquent\\Relations\\Relation",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/yassi/nova-nested-form/src/Traits/FillsSubAttributes.php",
            "line": 297,
            "function": "__call",
            "class": "Illuminate\\Database\\Eloquent\\Relations\\Relation",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/yassi/nova-nested-form/src/Traits/FillsSubAttributes.php",
            "line": 65,
            "function": "removeUntouched",
            "class": "Yassi\\NestedForm\\NestedForm",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/yassi/nova-nested-form/src/Traits/FillsSubAttributes.php",
            "line": 75,
            "function": "fillAttributeFromRequest",
            "class": "Yassi\\NestedForm\\NestedForm",
            "type": "->"
        },

workaround hard patch:

Index: vendor/yassi/nova-nested-form/src/Traits/FillsSubAttributes.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- vendor/yassi/nova-nested-form/src/Traits/FillsSubAttributes.php (date 1558347848683)
+++ vendor/yassi/nova-nested-form/src/Traits/FillsSubAttributes.php (date 1558347848683)
@@ -294,7 +294,7 @@
             if ($this->shouldRemoveAll) {
                 $ids = $model->{$this->viaRelationship}()->pluck('id');
             } else {
-                $ids = $model->{$this->viaRelationship}()->whereNotIn('id', $this->touched)->pluck('id');
+                $ids = $model->{$this->viaRelationship}()->whereNotIn($this->viaRelationship . '.id', $this->touched)->pluck($this->viaRelationship . '.id');
             }

             $request = CustomDeleteResourceRequest::createFrom($this->request->replace(['resources' => $ids]));
atmediauk commented 5 years ago

I think this bug might still exist. I get the following with a belongsToMany query.

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous (SQL: select `id` from `spokespeople` inner join `release_spokesperson` on `spokespeople`.`id` = `release_spokesperson`.`spokesperson_id` where `release_spokesperson`.`release_id` = 31 and `id` not in (11))