Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoadMultipleTrait #214

Closed
wants to merge 6 commits into from
Closed

LoadMultipleTrait #214

wants to merge 6 commits into from

Conversation

beastbytes
Copy link

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
Member

terabytesoftw commented Jul 15, 2022

Related: yiisoft/yii2#19284

@xepozz
Copy link
Contributor

xepozz commented Jul 15, 2022

What's a use case for these methods?

@beastbytes
Copy link
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
if ($model->load($data[$i], '') === true) {
$this->models[] = $model;
} else {
$this->models[] = $success = false;
Copy link
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
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
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.

None yet

5 participants