idealia/yii2-children-count-behavior

Behavior for counting records in the dependent objects and updating the relevant column after insert, edit and remove any child record.


Keywords
activerecord, yii, yii2
License
Apache-2.0

Documentation

yii2-children-count-behavior

Behavior for counting records in the dependent objects and updating the relevant column after insert, edit and remove any child record.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require idealia/yii2-children-count-behavior "*"

or add

"idealia/yii2-children-count-behavior": "*"

to the require section of your composer.json file.

Usage

public function behaviors()
{
     return [
         [
             'class' => ChildrenCountBehavior::className(),
             'countRelation' => 'getDocuments',
             'parentRelation' => 'getTask',
             'columnToUpdate' => 'document_count'
         ],
     ];
}