PHPackages                             ecommit/doctrine-orm-refetch - 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. [Database &amp; ORM](/categories/database)
4. /
5. ecommit/doctrine-orm-refetch

ActiveLibrary[Database &amp; ORM](/categories/database)

ecommit/doctrine-orm-refetch
============================

Refetch ORM Doctrine objects. Or detach all entities attached since a snapshot

v1.2.0(4w ago)13.5k↑30.8%1MITPHPPHP ^8.1CI passing

Since Feb 2Pushed 4w ago1 watchersCompare

[ Source](https://github.com/e-commit/doctrine-orm-refetch)[ Packagist](https://packagist.org/packages/ecommit/doctrine-orm-refetch)[ RSS](/packages/ecommit-doctrine-orm-refetch/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (22)Versions (8)Used By (0)

Doctrine ORM Refetch
====================

[](#doctrine-orm-refetch)

This library allows to

- re-fetch Doctrine ORM objects after clear the object manager
- detach all entities attached since a snapshot

[![Tests](https://github.com/e-commit/doctrine-orm-refetch/workflows/Tests/badge.svg)](https://github.com/e-commit/doctrine-orm-refetch/workflows/Tests/badge.svg)

Installation
------------

[](#installation)

To install doctrine-orm-refetch with Composer just run :

```
$ composer require ecommit/doctrine-orm-refetch
```

Usage
-----

[](#usage)

Create the utility (`$entityManager` is the Doctrine ORM entity manager):

```
use Ecommit\DoctrineOrmRefetch\RefetchManager;

$refetchManager = RefetchManager::create($entityManager);
```

### Refetch an object

[](#refetch-an-object)

```
$myObject = $refetchManager->getFetchedObject($myObject);
//or $refetchManager->refreshObject($myObject);
```

Example:

```
use Ecommit\DoctrineOrmRefetch\RefetchManager;

$refetchManager = RefetchManager::create($entityManager);

$author = $entityManager->getRepository(Author::class)->find(1);

$queryBuilder = $entityManager->getRepository(Book::class)->createQueryBuilder('b');
$queryBuilder->select('b')
    ->andWhere('b.bookId != :bookId')
    ->setParameter('bookId', 7);
$iterableResult = $queryBuilder->getQuery()->iterate();

$i = 0;
foreach ($iterableResult as $row) {
    ++$i;
    $book = current($row);

    if (!$book->getAuthors()->contains($author)) {
        $book->addAuthor($author);
    }

    if (0 === $i % 20) {
        //$author is managed
        $entityManager->flush();
        $entityManager->clear();
        //$author is not managed
        $author = $refetchManager->getObject($author);
        //$author is managed
    }
}

$entityManager->flush();
$entityManager->clear();
```

### Get collection by critera

[](#get-collection-by-critera)

```
$collection = $refetchManager->getCollectionFromCriteria($criteria, 'MyClass');
```

Example:

```
use Doctrine\Common\Collections\Criteria;
use Ecommit\DoctrineOrmRefetch\RefetchManager;

$refetchManager = RefetchManager::create($entityManager);

$ctiteria = Criteria::create()
    ->andWhere(Criteria::expr()->gt('authorId', 2));
$authors = $refetchManager->getCollectionFromCriteria($ctiteria, Author::class);

$queryBuilder = $entityManager->getRepository(Book::class)->createQueryBuilder('b');
$queryBuilder->select('b')
    ->andWhere('b.bookId != :bookId')
    ->setParameter('bookId', 9);
$iterableResult = $queryBuilder->getQuery()->iterate();

$i = 0;
foreach ($iterableResult as $row) {
    ++$i;
    $book = current($row);

    foreach ($authors as $author) {
        if (!$book->getAuthors()->contains($author)) {
            $book->addAuthor($author);
        }
    }

    if (0 === $i % 20) {
        $entityManager->flush();
        $entityManager->clear();
        $authors = $refetchManager->getCollectionFromCriteria($ctiteria, Author::class);
    }
}

$entityManager->flush();
$entityManager->clear();
```

### Snapshot

[](#snapshot)

Detach all entities attached since a snapshot (entities attached before the snapshot are kept)

```
use Ecommit\DoctrineOrmRefetch\SnapshotManager;

$snapshotManager = SnapshotManager::create($entityManager);

$author = $entityManager->getRepository(Author::class)->find(1);

$snapshotManager->snapshot();

$queryBuilder = $entityManager->getRepository(Book::class)->createQueryBuilder('b');
$queryBuilder->select('b')
    ->andWhere('b.bookId != :bookId')
    ->setParameter('bookId', 7);
$iterableResult = $queryBuilder->getQuery()->iterate();

$i = 0;
foreach ($iterableResult as $row) {
    ++$i;
    /** @var Book $book */
    $book = current($row);

    if (!$book->getAuthors()->contains($author)) {
        $book->addAuthor($author);
    }

    if (0 === $i % 2) {
        // $author and $book are managed
        $entityManager->flush();
        $snapshotManager->clear(); // Detach all entities attached since the snapshot
        // Only $author is managed
    }
}

$entityManager->flush();
$snapshotManager->clear();
```

License
-------

[](#license)

This librairy is under the MIT license. See the complete license in *LICENSE* file.

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance94

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~324 days

Recently: every ~352 days

Total

7

Last Release

29d ago

Major Versions

v0.2.0 → v1.0.02022-07-24

PHP version history (2 changes)v0.1.0PHP ^7.2|^8.0

v1.1.1PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/73191162d97fffaa1a23d23326a7a77fbaa94ce41e49cf4ee6cbf0b9c9800c80?d=identicon)[e-commit](/maintainers/e-commit)

---

Top Contributors

[![hlecorche](https://avatars.githubusercontent.com/u/188749?v=4)](https://github.com/hlecorche "hlecorche (51 commits)")

---

Tags

doctrinephprefetchsnapshotsnapshotdoctrinerefetch

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ecommit-doctrine-orm-refetch/health.svg)

```
[![Health](https://phpackages.com/badges/ecommit-doctrine-orm-refetch/health.svg)](https://phpackages.com/packages/ecommit-doctrine-orm-refetch)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M738](/packages/sylius-sylius)[api-platform/doctrine-common

Common files used by api-platform/doctrine-orm and api-platform/doctrine-odm

274.4M48](/packages/api-platform-doctrine-common)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[api-platform/doctrine-orm

Doctrine ORM bridge

294.4M92](/packages/api-platform-doctrine-orm)[doctrineencryptbundle/doctrine-encrypt-bundle

Encrypted symfony entity's by verified and standardized libraries

32510.9k](/packages/doctrineencryptbundle-doctrine-encrypt-bundle)

PHPackages © 2026

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