Skip to content

LoadMultipleTrait#214

Closed
beastbytes wants to merge 6 commits intoyiisoft:masterfrom
beastbytes:master
Closed

LoadMultipleTrait#214
beastbytes wants to merge 6 commits intoyiisoft:masterfrom
beastbytes:master

Conversation

@beastbytes
Copy link
Copy Markdown

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues comma-separated list of tickets # fixed by the PR, if any

Trait to be used in Form models.

Adds two methods:

loadMultiple() to load multiple models
getModels() to get the loaded models

#Usage

class MyFormModel extends FormModel
{
    use Yiisoft\Form\LoadMultipleTrait;

    ...
}

In an action

    ....

    $form = new MyFormModel();

    if ($form->loadMultiple($request->getParsedBody())) {
        foreach ($form->getModels() as $i => $model) {
            if (!$validator->validate($model)
                ->isValid()) {
                throw new \Exception("Validation failed at $i");
            }
        }

        // persist the models and send response
    }

@terabytesoftw
Copy link
Copy Markdown
Member

terabytesoftw commented Jul 15, 2022

Related: yiisoft/yii2#19284

@xepozz
Copy link
Copy Markdown
Member

xepozz commented Jul 15, 2022

What's a use case for these methods?

@beastbytes
Copy link
Copy Markdown
Author

Loading tabular data

@samdark samdark requested a review from a team July 16, 2022 11:03
@samdark samdark added the status:code review The pull request needs review. label Jul 16, 2022
Comment thread src/LoadMultipleTrait.php
if ($model->load($data[$i], '') === true) {
$this->models[] = $model;
} else {
$this->models[] = $success = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use several types (false or FormModel) in array of models is confused.

{
use TestTrait;

/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test need for success case.

@beastbytes beastbytes requested a review from vjik October 7, 2022 21:32
@vjik
Copy link
Copy Markdown
Member

vjik commented Dec 4, 2023

Closed in favor yiisoft/form-model#11

@vjik vjik closed this Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants