PHPackages                             huttopia/doctrine - 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. huttopia/doctrine

ActiveLibrary

huttopia/doctrine
=================

Add some features and fix to doctrine, without forking it

1.3.2(8y ago)02.5kMITPHPPHP &gt;=7.1.3

Since Jun 29Pushed 4y ago6 watchersCompare

[ Source](https://github.com/Huttopia/doctrine)[ Packagist](https://packagist.org/packages/huttopia/doctrine)[ RSS](/packages/huttopia-doctrine/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (9)Dependencies (8)Versions (14)Used By (0)

[![version](https://camo.githubusercontent.com/b6cb9fc1c7557e8a87bd94431d40bf8fa311005c0a81bdfb1a39d5d4da1d0395/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d312e332e322d677265656e2e737667)](https://github.com/huttopia/doctrine/releases/tag/1.3.2)[![symfony](https://camo.githubusercontent.com/16e84081c77426f0d1435bc9f1c1b371aa3286c8ed9d337608c92c5561e5ee57/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e312e332d626c75652e737667)](http://www.php.net)[![symfony](https://camo.githubusercontent.com/c5b40de009c207108345e0c5cf99370981cb9afc2bdbb535bbc96a6c5c62c786/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f637472696e652f6f726d2d322e352e362d626c75652e737667)](http://www.doctrine-project.org)[![symfony](https://camo.githubusercontent.com/3733bf3c5e515be2b339fb672bc2314ee39db73992807c215c9d29a33bffa79e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792f73796d666f6e792d253545332e302d626c75652e737667)](https://symfony.com/)[![Lines](https://camo.githubusercontent.com/ef00237ddfe8c42425872b73a61660de359b4ad1379a114b768abb30989ce66c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532306c696e65732d313531312d677265656e2e737667)](https://camo.githubusercontent.com/ef00237ddfe8c42425872b73a61660de359b4ad1379a114b768abb30989ce66c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532306c696e65732d313531312d677265656e2e737667)[![Total Downloads](https://camo.githubusercontent.com/9012d704209dd249e64a08389b108509fc0bd096dfbc0dae29dbef008cfa6691/68747470733a2f2f706f7365722e707567782e6f72672f687574746f7069612f646f637472696e652f646f776e6c6f616473)](https://camo.githubusercontent.com/9012d704209dd249e64a08389b108509fc0bd096dfbc0dae29dbef008cfa6691/68747470733a2f2f706f7365722e707567782e6f72672f687574746f7069612f646f637472696e652f646f776e6c6f616473)

### huttopia/doctrine

[](#huttopiadoctrine)

Doctrine is a really good ORM, with nice features, we love it !

But, to be honest, no major version since 2 april 2015 (2.6 is here, but too much bugs for now), several bugs are not fixed and it takes too much time to create patch version when you create a PR to fix something.

So, we decided to create *huttopia/doctrine*, to fix what we need, without waiting for a release. We can add features too.

We decide to not fork Doctrine, because we want to follow Doctrine releases. Forking it now is nice and amazing, but in 2 years...

When we need to override a class, we do it with [steevanb/composer-overload-class](https://github.com/steevanb/composer-overload-class). That's a good way when you need it, without renaming namespace everywhere (we can't, that's not a fork ;)).

[Changelog](changelog.md)

### Installation

[](#installation)

Add it to your composer.json :

```
composer require huttopia/doctrine ^1.3.2
```

Register HuttopiaDoctrineBundle :

```
# app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles(): array
    {
        $bundles = [
            new Huttopia\Doctrine\Bridge\Symfony3\HuttopiaDoctrineBundle()
        ];

        return $bundles;
    }
}
```

Change Doctrine configuration :

```
# app/config/config.yml

doctrine:
    orm:
        repository_factory: huttopia.doctrine.repository_factory
        default_repository_class: Huttopia\Doctrine\Orm\EntityRepository
```

Configuration :

```
# app/config/config.yml

huttopia_doctrine:
    repository_factory_service: huttopia.doctrine.repository_factory # this is default value
```

### Doctrine bugs

[](#doctrine-bugs)

Bugs who are fixed or not fixed by Doctrine, for some reasons :

- [fixed by steevanb/doctrine-events](https://github.com/steevanb/doctrine-events) Fix a Doctrine UnitOfwork bug with extraUpdates, who are not removed when you add and remove your entity before calling flush()
- [\#6042 (not fixed)](https://github.com/doctrine/doctrine2/issues/6042) getId() lazy load entity if getId() is in trait : not fixed, just to remember why we don't use trait for getId()
- [\#6110 (fixed)](https://github.com/doctrine/doctrine2/pull/6110) Clear $this-&gt;collection even when empty, to reset keys
- [\#6509 (fixed here)](https://github.com/doctrine/doctrine2/issues/6509) PersistentCollection::clear() and removeElement() with orphanRemoval will remove your entity, although you don't want

For now, we fix 2.5.6 for doctrine/orm dependency : &gt;2.5.6 and 2.6 has wrong tag (some dependencies are on dev-master, whithout version), some BC etc.

We will change it when 2.6 will be more tested.

### Repositories as service

[](#repositories-as-service)

Yes, you need it too ;) Repositories as service is one of the biggest improvement.

Now, we can define your repository as service, with huttopia.repository tag :

```
services:
    bar_repository:
        class: Foo\Repository\BarRepository
        arguments: ['@service', '%parameter%']
        tags:
            - { name: huttopia.repository, entity: Foo\Bar }
```

You need to change *extends Doctrine\\ORM\\EntityRepository* by *extends Huttopia\\Doctrine\\Orm\\EntityRepository* in your repositories.

Take care, our repository remove magic methods (findOneById() for example).

But it add a lot of methods :

- getClassName(): string
- getClassTableName(): string
- createQueryBuilderWithoutSelect(string $alias, string $indexBy = null): QueryBuilder
- get(int $id): Entity
- getOneBy(array $criteria, array $orderBy = null): Entity
- countAll(): int
- countBy(array $params): int
- findReadOnlyBy(array $criteria, array $fields = null, array $orderBy = null, $limit = null, $offset = null): array
- getPartialReference(int $id)

Difference between find() and get(), and findOneBy() and getOneBy() : when entity is not found, find() will return null, as get() will throw an exception.

When you use PARTIAL, you can call createQueryBuilderWithoutSelect() instead of createQueryBuilder(), who will not select all root entity fields.

### Remove useless discriminator in SQL for single table inheritance

[](#remove-useless-discriminator-in-sql-for-single-table-inheritance)

With SINGLE\_TABLE\_INHERITANCE entities, Doctrine add discriminator columns into all SQL queries.

But if you want to query all entities, Doctrine add useless WHERE clause with discriminator : not really good for performances ;)

Huttopia\\Doctrine\\SqlWalker\\IgnoreDiscriminator override Doctrine SqlWalker, to add WHERE clause only when needed.

Add it for a single query :

```
use Huttopia\Doctrine\SqlWalker\IgnoreDiscriminator

$queryBuilder
    ->getQuery()
    ->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, IgnoreDiscriminator::class);
```

Add it for all queries :

```
# app/AppKernel.php

class AppKernel
{
    public function boot(): void
    {
        parent::boot();

        foreach ($this->getContainer()->get('doctrine')->getManagers() as $manager) {
            if ($manager instanceof EntityManagerInterface) {
                $manager->getConfiguration()->setDefaultQueryHint(
                    Query::HINT_CUSTOM_OUTPUT_WALKER,
                    IgnoreDiscriminator::class
                );
            }
        }
    }
}
```

### [\#6509](https://github.com/doctrine/doctrine2/issues/6509) Fix PersistentCollection orphanRemoval management

[](#6509-fix-persistentcollection-orphanremoval-management)

When you call *remove()*, *removeElement()* or *clear()* on *PersistentCollection*, and your manyToOne configuration define *orphanRemoval* as true, PersistentCollection will add your deleted entity in UnitOfWork::$orphanRemovals.

flush() will read UnitOfWork::$orphanRemovals, and delete all entities, although they are deleted then added.

So, if you remove an entity, then add it again, then flush(), finally, your entity will be deleted.

To fix it, we override *PersistentCollection*, and unschedule orphanRemovals when we add entity to PersistentCollection.

See [ComposerOverloadClass installation](https://github.com/steevanb/composer-overload-class).

Override *PersistentCollection* to fix it :

```
{
    "extra": {
        "composer-overload-class": {
            "Doctrine\\ORM\\PersistentCollection": {
                "original-file": "vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php",
                "overload-file": "vendor/huttopia/doctrine/ComposerOverloadClass/Orm/PersistentCollection.php",
                "replace": true
            }
        }
    }
}
```

### Enable steevanb/doctrine-events

[](#enable-steevanbdoctrine-events)

It will replace EntityManager, to add some events : onCreateEntityOverrideLocalValues, onCreateEntityDefineFieldValues, onNewEntityInstance etc.

See [Installation](https://github.com/steevanb/doctrine-events/blob/master/README.md#installation) to install it.

### Enable steevanb/doctrine-entity-merger

[](#enable-steevanbdoctrine-entity-merger)

When you use PARTIAL in DQL, you retrieve only fields you need, instead of all Entity fields.

But, if you execute 2 PARTIAL on same entity, but not same fields, your final entity will not have second PARTIAL data, only first one is hydrated.

See [Installation](https://github.com/steevanb/doctrine-entity-merger#installation) to install it.

### Enable steevanb/doctrine-read-only-hydrator

[](#enable-steevanbdoctrine-read-only-hydrator)

See [Benchmark](https://github.com/steevanb/doctrine-read-only-hydrator#benchmark), you will understand why we use ReadOnlyHydrator ;)

See [Installation](https://github.com/steevanb/doctrine-read-only-hydrator#installation) to install it.

### Enable steevanb/doctrine-stats

[](#enable-steevanbdoctrine-stats)

[steevanb/doctrine-stats](https://github.com/steevanb/doctrine-stats) add lot of statistics about queries, hydration time, lazy loaded entities, etc.

See [Installation](https://github.com/steevanb/doctrine-stats#installation) to install it.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 69.6% 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 ~12 days

Total

9

Last Release

3142d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4fc8590c16dc26e7e8248ae77dcae6ea1d3475331b0f0359f3dbd6535d4806d1?d=identicon)[huttopia](/maintainers/huttopia)

---

Top Contributors

[![steevanb](https://avatars.githubusercontent.com/u/5063383?v=4)](https://github.com/steevanb "steevanb (16 commits)")[![ZeMarine](https://avatars.githubusercontent.com/u/158932?v=4)](https://github.com/ZeMarine "ZeMarine (6 commits)")[![acoquoin](https://avatars.githubusercontent.com/u/990484?v=4)](https://github.com/acoquoin "acoquoin (1 commits)")

---

Tags

doctrine2phpphp7php71symfony

### Embed Badge

![Health badge](/badges/huttopia-doctrine/health.svg)

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

###  Alternatives

[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[kilik/table

Symfony Ajax Datagrid Bundle for doctrine entities

3361.4k](/packages/kilik-table)[pixelfederation/doctrine-resettable-em-bundle

Symfony bundle for decorating default entity managers using a resettable decorator.

20113.5k](/packages/pixelfederation-doctrine-resettable-em-bundle)[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.

1022.4k](/packages/rcsofttech-audit-trail-bundle)[ahmed-bhs/doctrine-doctor

Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.

813.1k](/packages/ahmed-bhs-doctrine-doctor)[easycorp/easyadmin-demo

EasyAdmin Demo Application

145.7k](/packages/easycorp-easyadmin-demo)

PHPackages © 2026

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