2017 © Pedro Peláez
 

yii2-extension yii2-relation-trait

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

image

deadmantfa/yii2-relation-trait

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

  • Wednesday, February 14, 2018
  • by deadmantfa
  • Repository
  • 1 Watchers
  • 0 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 38 Forks
  • 0 Open issues
  • 29 Versions
  • 3 % Grown

The README.md

yii2-relation-trait

Note: This is not the official extension by @mootensai.
I am not the creator of the original extension. I have made bug fixes and improvements that suit my use case.
Feel free to use it or refer to the official package at mootensai/yii2-relation-trait., (*1)

Yii 2 Models add functionality for loading related models via loadAll($POST) and transactional saving via saveAll().
It also supports soft delete and soft restore features., (*2)

Works best with mootensai/yii2-enhanced-gii., (*3)

Badges

Latest Stable Version License Total Downloads Monthly Downloads Daily Downloads, (*4)

Installation

The preferred way to install this extension is through Composer., (*5)

Either run, (*6)

composer require deadmantfa/yii2-relation-trait

or add, (*7)

"deadmantfa/yii2-relation-trait": "^2.0.0"

to the require section of your application's composer.json file., (*8)

Usage in the Model

use deadmantfa\relation\RelationTrait;

class MyModel extends \yii\db\ActiveRecord
{
    use RelationTrait;

    // ...
}

Controller Usage

The extension expects a normal array of POST data. For example:, (*9)

[
    $_POST['ParentClass'] => [
        'attr1' => 'value1',
        'attr2' => 'value2',
        // Has many
        'relationName' => [
            [ 'relAttr' => 'relValue1' ],
            [ 'relAttr' => 'relValue2' ]
        ],
        // Has one
        'relationName' => [
            'relAttr1' => 'relValue1',
            'relAttr2' => 'relValue2'
        ]
    ]
];

In your controller:, (*10)

$model = new ParentClass();
if ($model->loadAll(Yii::$app->request->post()) && $model->saveAll()) {
    return $this->redirect(['view', 'id' => $model->id]);
}

Features, (*11)

  1. Transaction Support a. Your data changes are atomic (ACID compliant).
  2. Normal save() a. Behaviors still work as usual since it’s built on top of Yii’s ActiveRecord.
  3. Validation a. Errors from related models appear via errorSummary(), e.g. text MyRelatedClass #2: [Error message]
  4. UUID or Auto-Increment Works with any PK strategy, including mootensai/yii2-uuid-behavior.
  5. Soft Delete By defining $_rt_softdelete in your model constructor (and $_rt_softrestore for restoring), you can softly mark rows as deleted instead of physically removing them., (*12)

        private $_rt_softdelete;
        private $_rt_softrestore;
    
        public function __construct($config = [])
        {
            parent::__construct($config);
    
            $this->_rt_softdelete = [
                'is_deleted' => 1,
                'deleted_by' => Yii::$app->user->id,
                'deleted_at' => date('Y-m-d H:i:s'),
            ];
    
            $this->_rt_softrestore = [
                'is_deleted' => 0,
                'deleted_by' => null,
                'deleted_at' => null,
            ];
        }
    

Array Outputs

print_r($model->getAttributesWithRelatedAsPost());

Produces a POST-like structure with the main model and related arrays., (*13)

print_r($model->getAttributesWithRelated());

Produces a nested structure under [relationName] => [...]., (*14)

Contributing or Reporting Issues

Please open an issue or submit a PR if you find a bug or have an improvement idea., (*15)


Disclaimer

This package is a fork or an alternative to mootensai/yii2-relation-trait. All credit to @mootensai for the initial code. This is not meant to replace the original package but rather provide bug fixes and enhancements under a different namespace., (*16)

The Versions

14/02 2018

dev-master

9999999-dev http://github.com/deadmantfa/yii2-relation-trait

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya
by Wenceslaus Dsilva

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

14/02 2018

1.1.15

1.1.15.0 http://github.com/deadmantfa/yii2-relation-trait

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya
by Wenceslaus Dsilva

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

11/02 2018

1.1.14

1.1.14.0 http://github.com/deadmantfa/yii2-relation-trait

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya
by Wenceslaus Dsilva

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

11/02 2018

1.1.13

1.1.13.0 http://github.com/deadmantfa/yii2-relation-trait

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya
by Wenceslaus Dsilva

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

09/02 2018

1.1.12

1.1.12.0 http://github.com/deadmantfa/yii2-relation-trait

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

  Sources   Download

BSD-3-Clause

The Requires

 

by Yohanes Candrajaya
by Wenceslaus Dsilva

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

09/02 2018

1.1.11

1.1.11.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
by Wenceslaus Dsilva

yii2 load related transaction save relation loadwithrelation savewithrelation saveall loadall

09/02 2018

1.1.10.1

1.1.10.1 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/02 2018

1.1.10

1.1.10.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/02 2018

1.1.9

1.1.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

18/10 2017

1.1.8

1.1.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

28/09 2017

1.1.7

1.1.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

23/07 2017

1.1.6

1.1.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

12/07 2017

1.1.5

1.1.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

12/07 2017

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1 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 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