Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ability to merge detached entities #9488

Merged
merged 1 commit into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions UPGRADE.md
@@ -1,5 +1,15 @@
# Upgrade to 3.0

## BC BREAK: Remove ability to merge detached entities

Merge semantics was a poor fit for the PHP "share-nothing" architecture.
In addition to that, merging caused multiple issues with data integrity
in the managed entity graph, which was constantly spawning more edge-case
bugs/scenarios.

The method `UnitOfWork::merge()` has been removed. The method
`EntityManager::merge()` will throw an exception on each call.

## BC BREAK: Removed ability to partially flush/commit entity manager and unit of work

The following methods don't accept a single entity or an array of entities anymore:
Expand Down
32 changes: 6 additions & 26 deletions lib/Doctrine/ORM/EntityManager.php
Expand Up @@ -4,13 +4,13 @@

namespace Doctrine\ORM;

use BadMethodCallException;
use Doctrine\Common\EventManager;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\LockMode;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Exception\EntityManagerClosed;
use Doctrine\ORM\Exception\InvalidHydrationMode;
use Doctrine\ORM\Exception\ManagerException;
Expand Down Expand Up @@ -542,35 +542,15 @@ public function detach($entity): void
}

/**
* Merges the state of a detached entity into the persistence context
* of this EntityManager and returns the managed copy of the entity.
* The entity passed to merge will not become associated/managed with this EntityManager.
* Not supported.
*
* @deprecated 2.7 This method is being removed from the ORM and won't have any replacement
* @param object $object
*
* @param object $entity The detached entity to merge into the persistence context.
*
* @return object The managed copy of the entity.
*
* @throws ORMInvalidArgumentException
* @throws ORMException
* @psalm-return never
*/
public function merge($entity): object
public function merge($object): object
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep the method for compatibility with Persistence 2. We can drop it as soon as we move to Persistence >= 3.

{
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/8461',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0.',
__METHOD__
);

if (! is_object($entity)) {
throw ORMInvalidArgumentException::invalidObject('EntityManager#merge()', $entity);
}

$this->errorIfClosed();

return $this->unitOfWork->merge($entity);
throw new BadMethodCallException('The merge operation is not supported.');
}

/**
Expand Down
135 changes: 0 additions & 135 deletions lib/Doctrine/ORM/Mapping/Reflection/ReflectionPropertiesGetter.php

This file was deleted.