-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |