Download the PHP package huttopia/doctrine without Composer
On this page you can find all versions of the php package huttopia/doctrine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download huttopia/doctrine
More information about huttopia/doctrine
Files in huttopia/doctrine
Package doctrine
Short Description Add some features and fix to doctrine, without forking it
License MIT
Informations about the package doctrine
huttopia/doctrine
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. That's a good way when you need it, without renaming namespace everywhere (we can't, that's not a fork ;)).
Changelog
Installation
Add it to your composer.json :
Register HuttopiaDoctrineBundle :
Change Doctrine configuration :
Configuration :
Doctrine bugs
Bugs who are fixed or not fixed by Doctrine, for some reasons :
- fixed by 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) getId() lazy load entity if getId() is in trait : not fixed, just to remember why we don't use trait for getId()
- #6110 (fixed) Clear $this->collection even when empty, to reset keys
- #6509 (fixed here) 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 : >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
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 :
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
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 :
Add it for all queries :
#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.
Override PersistentCollection to fix it :
Enable steevanb/doctrine-events
It will replace EntityManager, to add some events : onCreateEntityOverrideLocalValues, onCreateEntityDefineFieldValues, onNewEntityInstance etc.
See Installation to install it.
Enable steevanb/doctrine-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 to install it.
Enable steevanb/doctrine-read-only-hydrator
See Benchmark, you will understand why we use ReadOnlyHydrator ;)
See Installation to install it.
Enable steevanb/doctrine-stats
steevanb/doctrine-stats add lot of statistics about queries, hydration time, lazy loaded entities, etc.
See Installation to install it.
All versions of doctrine with dependencies
doctrine/orm Version 2.5.6
doctrine/doctrine-bundle Version ^1.6
doctrine/doctrine-cache-bundle Version ^1.3
steevanb/doctrine-read-only-hydrator Version ^2.2
steevanb/doctrine-entity-merger Version ^1.0
steevanb/doctrine-events Version ^1.2
steevanb/composer-overload-class Version ^1.3