2017 © Pedro Peláez
 

yii2-extension yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

image

stesi/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  • Thursday, December 21, 2017
  • by moccia.f
  • Repository
  • 1 Watchers
  • 0 Stars
  • 74 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 38 Forks
  • 0 Open issues
  • 19 Versions
  • 4 % Grown

The README.md

yii2-relation-trait

Yii 2 Models add functionality for load with relation (loadAll($POST)), & transactional save with relation (saveAll()), (*1)

Latest Stable Version License Total Downloads Monthly Downloads Daily Downloads Join the chat at https://gitter.im/mootensai/yii2-relation-trait Bitdeli Badge, (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

$ composer require 'stesi/yii2-relation-trait:dev-master'

or add, (*5)

"stesi/yii2-relation-trait": "*"

to the require section of your composer.json file., (*6)

Usage At Model

class MyModel extends ActiveRecord{
    use \mootensai\relation\RelationTrait;
}

Array Input & Usage At Controller

It takes a normal array of POST. This is the example, (*7)

// sample at controller
//$_POST['ParentClass'] = ['attr1' => 'value1','attr2' => 'value2'];
//$_POST['RelatedClass'][0] = ['attr1' => 'value1','attr2' => 'value2'];      
if($model->loadAll(Yii:$app->request->post()) && $model->saveAll()){
    return $this->redirect(['view', 'id' => $model->id, 'created' => $model->created]);
}

Features

Array Output

// I use this to send model & related through JSON / Serialize
print_r($model->getAttributesWithRelatedAsPost());
Array
(
    [MainClass] => Array
        (
            [attr1] => value1
            [attr2] => value2
        )

    [RelatedClass] => Array
        (
            [0] => Array
                (
                    [attr1] => value1
                    [attr2] => value2
                )
        )

)
print_r($model->getAttributesWithRelated());
Array
(
    [attr1] => value1
    [attr2] => value2
    [relationName] => Array
        (
            [0] => Array
                (
                    [attr1] => value1
                    [attr2] => value2
                )
        )
)

Use Transaction

So your data will be atomic (see : http://en.wikipedia.org/wiki/ACID), (*8)

Use Normal Save

So your behaviors still works, (*9)

Add Validation At Main Model

$form->errorSummary($model);

will give you, (*10)

<<Related Class Name>> #<<index + 1>> : <<error message>>
My Related Model #1 : Attribute is required

It Works On Auto Incremental PK Or Not (I Have Tried Use UUID)

See here if you want to use my behavior : https://github.com/mootensai/yii2-uuid-behavior, (*11)

To Do

Test it on another DB. I only test it on MySQL., (*12)

I'm open for any improvement, (*13)

The Versions

21/12 2017

dev-master

9999999-dev https://github.com/stesi/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

21/12 2017

1.1.5.2

1.1.5.2 https://github.com/stesi/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

20/12 2017

1.1.5.1

1.1.5.1 https://github.com/stesi/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

06/10 2017

1.1.5

1.1.5.0 https://github.com/stesi/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

08/07 2016

1.1.4

1.1.4.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

11/06 2016

1.1.3

1.1.3.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

08/06 2016

1.1.2

1.1.2.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

26/02 2016

1.1.1

1.1.1.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

24/02 2016

1.1.0

1.1.0.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

22/02 2016

1.0.9

1.0.9.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

17/02 2016

1.0.8

1.0.8.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

27/07 2015

1.0.7

1.0.7.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

24/07 2015

1.0.6

1.0.6.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

08/07 2015

1.0.5

1.0.5.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

10/06 2015

1.0.4

1.0.4.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

09/06 2015

1.0.3

1.0.3.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

09/06 2015

1.0.2

1.0.2.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

09/06 2015

1.0.1

1.0.1.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

03/06 2015

1.0.0

1.0.0.0 http://github.com/mootensai/yii2-relation-trait

Yii 2 Models load with relation, & transaction save with relation

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall