承接 goldfinch/eagerloading 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

goldfinch/eagerloading

最新稳定版本:v0.6.2

Composer 安装命令:

composer require goldfinch/eagerloading

包简介

Eager loading for SilverStripe 4

关键字:

README 文档

README

Scrutinizer Code Quality Build Status Code Coverage

Attempt to solve N+1 problem in SilverStripe 4.

Usage

MyModelClass::get()->with(['Relation1','Relation2'])->filter(...);

It does not require huge configuration - only one function to be added to the query builder chain : ->with([..relations...]). This will result in the final DataList to be presented by the EagerLoadedDataList class that handles the eager loading.

The module takes advantage of DataList::getGenerator() to query for and attach the related records only when needed.

Installation

composer require goldfinch/eagerloading

Every DataObject that has has_one/many_many/belongs_many_many which you wish to have eagerloaded must include EagerLoaderMultiAccessor (see below).

Features

Read the docs for full explanation.

Quick start

1. Add the following trait to all your models to use $has_many, $many_many, $belongs_meny_many:

class MyClass extends DataObject {
    use Gurucomkz\EagerLoading\EagerLoaderMultiAccessor;

    // ...
}

If you have your own __call() read Using with $has_many/$many_many.

2. Declare private static $eager_loading to boost ModelAdmin's GridField output.

class YourClass extends DataObject
{
    private static $eager_loading = [
        'Relation1',
        'Relation1.Relation4',
        'Relation2',
        'Relation3',
    ];
}

TODO

  • for ->with(['RelLevel1.RelLevel2']) - do not query for RelLevel1 IDs twice.
  • for ->with(['RelLevel1','RelLevel1.RelLevel2']) - do not query for RelLevel1 IDs thrice.

Reporting Issues

Please create an issue for any bugs you've found, or features you're missing.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2024-03-18