mootensai / yii2-enhanced-gii

Enhanced Yii2 Gii (generator) that generates related Models & CRUD
MIT License
203 stars 98 forks source link

Bug - when updating model + model related with dynamic form - duplicated entries on DB #138

Closed alvarolordelo closed 5 years ago

alvarolordelo commented 6 years ago

Hi folks, version:

mootensai/yii2-enhanced-gii | 9999999-dev mootensai/yii2-jsblock 1.0.0.0 mootensai/yii2-optimistic-lock-validator 0.0.1.0 mootensai/yii2-relation-trait 1.1.8.0

I'm using the default crud with yii2-enhanced, when I perform update action the model related is being duplicated, what I did to solve it, sent the table related id in the dynamic form with label = ' empty 'id'=>['type' => TabularForm::INPUT_HIDDEN, 'label' => ''], If not that way after the update the record it gets duplicated on my table.

By default, gii isn't creating the table ID on the dynamic form. I did it manually. I will put here what it sends before and after I add the id field. BEFORE image

And now after including the id on the dynamic form. image

What I get from the difference between them is that - sending the row ID made the action perform as expected. And stopped the duplicated row on my table.

cgernert commented 6 years ago

I also noticed this behaviour. It seems to be a quirk of the Kartik TabularForm.

cgernert commented 6 years ago

The saveAll() function needs the id to distinguish between existing and new records. Without id it will not know if the record was already existent in the DB and create a new one.

The id get inserted into the POST only if the TabularForm is configured as you described above Head over to https://github.com/kartik-v/yii2-builder and see, what info you can get about this behaviour