PHPackages                             yiister/yii2-mappable-ar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. yiister/yii2-mappable-ar

ActiveYii2-extension[Database &amp; ORM](/categories/database)

yiister/yii2-mappable-ar
========================

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

1.0.5(9y ago)197891[1 issues](https://github.com/yiister/yii2-mappable-ar/issues)[1 PRs](https://github.com/yiister/yii2-mappable-ar/pulls)BSD-3-ClausePHPPHP &gt;=5.4.0

Since Mar 20Pushed 9y ago6 watchersCompare

[ Source](https://github.com/yiister/yii2-mappable-ar)[ Packagist](https://packagist.org/packages/yiister/yii2-mappable-ar)[ Docs](https://github.com/yiister/yii2-mappable-ar)[ RSS](/packages/yiister-yii2-mappable-ar/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

Yii2 mappable ActiveRecord
==========================

[](#yii2-mappable-activerecord)

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

[![Build Status](https://camo.githubusercontent.com/af573941b243475a2a88544aca28b1799ae1c0b12dc8311fb791d0da490026dc/68747470733a2f2f7472617669732d63692e6f72672f796969737465722f796969322d6d61707061626c652d61722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yiister/yii2-mappable-ar)[![codecov.io](https://camo.githubusercontent.com/1ac827eab5dcbd10d48e547755e98d41aacc8e204abc5fd510d464160fcf95fe/68747470733a2f2f636f6465636f762e696f2f6769746875622f796969737465722f796969322d6d61707061626c652d61722f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/yiister/yii2-mappable-ar?branch=master)

[Russian documentation](docs/ru).

How it works
------------

[](#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.

By the way the next methods are allowed:

- `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
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

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

```

or add

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

to the `require` section of your composer.json.

Setting
-------

[](#setting)

The extension supports the next settings:

- `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';`.

Using
-----

[](#using)

Just add `use yiister\mappable\ActiveRecordTrait;` to your model for using an identityMap. You got all features after it.

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

Example:

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

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~21 days

Total

6

Last Release

3551d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.5.0

1.0.1PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b39988f8d3bfe24528079c8e623dfcf53bb2e44052866965a8a9347b0781aea0?d=identicon)[fps01](/maintainers/fps01)

---

Top Contributors

[![fps01](https://avatars.githubusercontent.com/u/2114997?v=4)](https://github.com/fps01 "fps01 (30 commits)")

---

Tags

yii2extensionactive-recordbackendutilsmappablearIdentity map

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/yiister-yii2-mappable-ar/health.svg)

```
[![Health](https://phpackages.com/badges/yiister-yii2-mappable-ar/health.svg)](https://phpackages.com/packages/yiister-yii2-mappable-ar)
```

###  Alternatives

[voskobovich/yii2-linker-behavior

This behavior makes it easy to maintain many-to-many and one-to-many relations in your ActiveRecord models.

79330.6k9](/packages/voskobovich-yii2-linker-behavior)[dmstr/yii2-migrate-command

Console Migration Command with multiple paths/aliases support

31297.1k6](/packages/dmstr-yii2-migrate-command)[dmstr/yii2-db

Database extensions

19656.2k6](/packages/dmstr-yii2-db)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
