-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Deprecate EntityRepository#clear() #7922
Comments
Help please! What is the current solution? The documentation is not up to date: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/batch-processing.html Example: $demoA = new DemoA();
$demoA->setName('Demo');
$entityManager->persist($demoA);
$entityManager->flush();
while (/* many entities .. */) {
$demoB = new DemoB();
$demoB->setDemoA($demoA);
$entityManager->persist($demoB);
$entityManager->flush();
$entityManager->detach($demoB); // ERROR: Method Doctrine\\ORM\\EntityManager::detach() is deprecated and will be removed in Doctrine ORM 3.0
} |
Yes, the docs will require updating there 👍 @danielspk check |
Handled by #7928 Documentation will be sorted out by another PR. |
@Ocramius I think
|
@danielspk if your code is your simple as your example, then it should be converted to this: $demoA = new DemoA();
$demoA->setName('Demo');
$entityManager->persist($demoA);
$entityManager->flush();
$entityManager->clear(); // we don't need anything in the UoW
while (/* many entities .. */) {
$demoB = new DemoB();
$demoB->setDemoA($entityManager->getReference(DemoA::class, $demoA->getId()); // assuming that `getId()` is how you get the identifier
$entityManager->persist($demoB);
$entityManager->flush();
$entityManager->clear();
}
Ideally, nobody would need that. Managing the UoW is an internal operation that might affect the behaviour of the ORM, hence our move to try to regain control over it. In the meantime, (if you really really really really really want to detach stuff and you're aware that you may have to deal with dragons) you can do Nevertheless your comment isn't related to this issue, since you're talking about |
Thank you very much @lcobucci His example is enlightening. In my case, after the loop, I need to use $ demoA again, but once again accessing the database is not expensive, it simply requires a refactor. Under these discussions, do you think it is worthwhile to make a refactor to migrate to version 2.7 or will it simply be better to wait for 2.8 when you are more certain? Cheers |
Using the L2C would also make this even less expensive - but you'd have to check if it's applicable to your use cases.
Triggering I'd suggest you to always try to migrate to the latest versions to reduce your maintenance burden but I can't tell how much effort is involved in your app. I'd also say for you to be as away from the UoW as possible but I understand that it's sometimes inevitable. |
That method calls
EntityManager#clear()
with an argument, which won't be allowed anymore on v3.0.We must add a
@deprecated
annotation (without atrigger_error()
since it's already handled byEntityManager#clear()
).Context on the why: #7925 (comment)
The text was updated successfully, but these errors were encountered: