PHPackages                             goldfinch/eagerloading - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. goldfinch/eagerloading

ActiveSilverstripe-vendormodule[Utility &amp; Helpers](/categories/utility)

goldfinch/eagerloading
======================

Eager loading for SilverStripe 4

v0.6.2(2y ago)0146BSD-3-ClausePHP

Since Mar 18Pushed 2y agoCompare

[ Source](https://github.com/goldfinch/silverstripe-eagerloading)[ Packagist](https://packagist.org/packages/goldfinch/eagerloading)[ RSS](/packages/goldfinch-eagerloading/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

Silverstripe EagerLoading
=========================

[](#silverstripe-eagerloading)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3a87e7e161f8942555ed5e2a136ba06e6ba9da42d93aaeaf8772fafb1c683925/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f67757275636f6d6b7a2f73696c7665727374726970652d65616765726c6f6164696e672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gurucomkz/silverstripe-eagerloading/?branch=master)[![Build Status](https://camo.githubusercontent.com/6a71944f3cbacdeeb5b9a72c7618fbf3e581f338fb1477196cfa68c79405ce29/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f67757275636f6d6b7a2f73696c7665727374726970652d65616765726c6f6164696e672f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gurucomkz/silverstripe-eagerloading/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/eb2efa64f56f06d3fc004f3adefbe65a7bd590f3f9cc6007b5f793bb694b4a3f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f67757275636f6d6b7a2f73696c7665727374726970652d65616765726c6f6164696e672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gurucomkz/silverstripe-eagerloading/?branch=master)

Attempt to solve [N+1 problem](https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping) in SilverStripe 4.

Usage
-----

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

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

[](#features)

- [Using with $has\_one / $belongs\_to](docs/en/Using_With_HasOne.md)
- [Using with $has\_many / $many\_many / $belongs\_many\_many](docs/en/Using_With_HasMany.md)
- [Boosting GridField output](docs/en/Boosting_GridField.md)
- [Boosting CSV export](docs/en/Boosting_CSV_Export.md)

Read the docs for full explanation.

Quick start
-----------

[](#quick-start)

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

[](#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](docs/en/Using_With_HasMany.md).

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

[](#2-declare-private-static-eager_loading-to-boost-modeladmins-gridfield-output)

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

TODO
----

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

[](#reporting-issues)

Please [create an issue](https://github.com/gurucomkz/silverstripe-eagerloading/issues) for any bugs you've found, or features you're missing.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 90% 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 ~0 days

Total

2

Last Release

790d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2291826?v=4)[goldfinch](/maintainers/goldfinch)[@goldfinch](https://github.com/goldfinch)

---

Top Contributors

[![gurucomkz](https://avatars.githubusercontent.com/u/12028675?v=4)](https://github.com/gurucomkz "gurucomkz (45 commits)")[![goldfinch](https://avatars.githubusercontent.com/u/2291826?v=4)](https://github.com/goldfinch "goldfinch (2 commits)")[![rasstislav](https://avatars.githubusercontent.com/u/9253113?v=4)](https://github.com/rasstislav "rasstislav (2 commits)")[![Acen](https://avatars.githubusercontent.com/u/924120?v=4)](https://github.com/Acen "Acen (1 commits)")

---

Tags

silverstripe

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/goldfinch-eagerloading/health.svg)

```
[![Health](https://phpackages.com/badges/goldfinch-eagerloading/health.svg)](https://phpackages.com/packages/goldfinch-eagerloading)
```

###  Alternatives

[silverstripe/multi-domain

Allows multiple domains to access one CMS instance, mapping them to different sections of the hierarchy

141.6k](/packages/silverstripe-multi-domain)

PHPackages © 2026

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