E
E
evilelf2016-03-23 20:36:39
Yii
evilelf, 2016-03-23 20:36:39

How to solve multiinsert problem in yii2?

All the best!
There is this code:

foreach ($attributes as $key => $val) {
                if (!$val) continue;
                $arFields = [
                    'worksheet_verify_id' => $wVerifyModel->primaryKey,
                    'meta_key' => $key,
                    'meta_val' => $val,
                ];
                if (!$wVerifyModel->isNewRecord) {
                    WorksheetVerifyMeta::deleteAll([
                        'worksheet_verify_id' => $wVerifyModel->primaryKey,
                        'meta_key' => $key,
                    ]);
                }
                $wVerifyMetaModel->attributes = $arFields;
                if($wVerifyMetaModel->getAttribute('ID')){
                    $wVerifyMetaModel->__unset('ID');
                }
                if ($wVerifyMetaModel->validate() && $wVerifyMetaModel->save()) {
                    $isSave = true;
                } else {
                    $this->addErrors($wVerifyMetaModel->getErrors());
                    $isSave = false;
                    break;
                }
            }

In $attributes the desired array.
Identifier in $wVerifyModel->primaryKey (present)
Problem:
Only the last one in the $attributes array is created in the database. Everything else feels like it's being ignored or overwritten.
How to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
evilelf, 2016-03-26
@evilelf

Colleagues, as I understand it, you just need to recreate the class.
Now I do exactly that. So I'll mark it as a solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question