yiister/yii2-mappable-ar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yiister/yii2-mappable-ar

Composer 安装命令:

composer require yiister/yii2-mappable-ar

包简介

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

README 文档

README

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

Build Status codecov.io

Russian documentation.

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

The preferred way to install this extension is through composer.

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

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

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

统计信息

  • 总下载量: 789
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 6
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-03-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固