Skip to content

Commit

Permalink
documentation (Close #2) [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
fps01 committed Jul 16, 2016
1 parent ad68e15 commit cf523a4
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
16 changes: 16 additions & 0 deletions CHANCHELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Yii2 Mappable ActiveRecord Change Log
=====================================

1.1.0 under development
-----------------------

1.0.1 July 26, 2016
-------------------

- New #2: Added a russian documentation (fps01)
- Enh #2: Fixed an english documentation (fps01)

1.0.0 March 20, 2016
--------------------

- Initial release
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
# 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://travis-ci.org/yiister/yii2-mappable-ar.svg?branch=master)](https://travis-ci.org/yiister/yii2-mappable-ar)
[![codecov.io](https://codecov.io/github/yiister/yii2-mappable-ar/coverage.svg?branch=master)](https://codecov.io/github/yiister/yii2-mappable-ar?branch=master)


[Russian documentation](docs/ru).

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

Expand Down Expand Up @@ -34,3 +50,10 @@ use yiister\mappable\ActiveRecordTrait;
```

to your model. After you may use `getById` and `getByAttribute` methods to get a model or an array.

Using
-----

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

**Warn!** Trait does not work if you override a `find` method in your model. This problem has a issue #7 on github.
42 changes: 42 additions & 0 deletions docs/ru/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Yii2 mappable ActiveRecord
==========================

Это расширение для Yii framework 2 которое дает возможность использовать паттерн `IdentityMap` для любой модели `ActiveRecord`.

Как это работает
----------------

`ActiveRecordTrait` переопределяет метод `find` модели. Этот метод создает свой собственный `ActiveQuery`. В последствии при вызове метода `one` (`all`) полученная модель (модели) сохраняются в `identityMap` в виде массива атрибутов (это экономит память). При последующих запросах, данные возвращаются без обращения к базе данных.

Кроме этого, доступны следующие методы:

- `getById(integer $id, boolean $asArray = false)` - получить модель или массив атрибутов (зависит от значения второго параметра) по первичному ключу;
- `getByAttribute(string $attribute, string $value, boolean $asArray = false)` - получить модель или массив атрибутов (зависит от значения второго параметра) по значению уникального атрибута;
- `getMap()` - получить все полученные модели из `identityMap` в виде массива атрибутов;
- `clearMap()` - очистить `identityMap`.

Установка
---------

Предпочтительным вариантом установки является [composer](http://getcomposer.org/download/).

Просто выполните команду

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

или добавьте

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

в секцию `require` вашего файла composer.json.

Использование
-------------

Для использования расширения достаточно указать для модели `use yiister\mappable\ActiveRecordTrait;`. После этого вам станут доступны все описанные возможности.

**Важно!** Если у вас переопределен метод `find`, то треит работать не будет. По этому поводу есть задача #7 на github.

0 comments on commit cf523a4

Please sign in to comment.