2017 © Pedro Peláez
 

yii2-extension yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

image

yiister/yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

  • Monday, October 10, 2016
  • by fps01
  • Repository
  • 6 Watchers
  • 21 Stars
  • 762 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Yii2 mappable ActiveRecord

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model., (*1)

Build Status codecov.io, (*2)

Russian documentation., (*3)

How it works

ActiveRecordTrait overrides a find method of model. This method creates a custom ActiveQuery. When one (all) method is called, a got model (models) save to identityMap as array of attributes (It saves a memory). The next requests return data without queries to data base., (*4)

By the way the next methods are allowed:, (*5)

  • getById(integer $id, boolean $asArray = false) - get a model or an array of attributes (It depends on second param value) by primary key;
  • getByAttribute(string $attribute, string $value, boolean $asArray = false) - get a model or an array of attributes (It depends on second param value) by unique attribute value;
  • getMap() - get all models from identityMap as array of attributes;
  • clearMap() - clear an identityMap.

Installation

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

Either run, (*7)

composer require --prefer-dist yiister/yii2-mappable-ar

or add, (*8)

"yiister/yii2-mappable-ar": "~1.0.0"

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

Setting

The extension supports the next settings:, (*10)

  • idAttribute - the primary key attribute (by default id);
  • identityMapMaxSize - the maximum elements count in identityMap (by default -1 = no limit);
  • uniqueAttributes - array of attribute names that contains unique values. It is used at the getByAttribute method.

For example, for change a primary key attribute to key add to your model public static $idAttribute = 'key';., (*11)

Using

Just add use yiister\mappable\ActiveRecordTrait; to your model for using an identityMap. You got all features after it., (*12)

Warn! If you have overridden find method in your model you have to call activeRecordTraitFind() method and work with its result., (*13)

Example:, (*14)

public static function find()
{
    $query = static::activeRecordTraitFind();
    // another work with $query
    return $query;
}

The Versions

10/10 2016

dev-master

9999999-dev https://github.com/yiister/yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 backend active-record utils ar mappable identity-map

10/10 2016

1.0.5

1.0.5.0 https://github.com/yiister/yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 backend active-record utils ar mappable identity-map

23/08 2016

1.0.4

1.0.4.0 https://github.com/yiister/yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 backend active-record utils ar mappable identity-map

20/07 2016

1.0.3

1.0.3.0 https://github.com/yiister/yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 backend active-record utils ar mappable identity-map

17/07 2016

1.0.2

1.0.2.0 https://github.com/yiister/yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 backend active-record utils ar mappable identity-map

16/07 2016

1.0.1

1.0.1.0 https://github.com/yiister/yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 backend active-record utils ar mappable identity-map

20/03 2016

1.0.0

1.0.0.0 https://github.com/yiister/yii2-mappable-ar

It is an extension for Yii framework 2 that gives an ability to use identity map for any ActiveRecord model.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

extension yii2 backend active-record utils ar mappable identity-map