mirror of
https://github.com/doctrine/orm.git
synced 2026-04-29 17:33:15 +02:00
DDC-2556: Proxy getId() different code generated when using Trait #3206
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jul 16, 2013).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user entering:
If I replace that code with a Trait with equal code and use it on the entity the proxy will be generated different.
Without trait:
With trait:
And in this code:
I get:
Doctrine\ORM\ORMException: The identifier id is missing for a query of EB\Core\KernelBundle\Entity\Common\Timezone
$campaign->getTimezone()->getId()
Is returning null.
About the findReadOnly is just a wrapper that will fetch from cache if not there fetch from DB, anyway if I change it to find() exact same problem
My versions of doctrine:
@doctrinebot commented on GitHub (Jul 16, 2013):
Comment created by @ocramius:
Is the problem here the repository or just the trait method?
Can you please clean up the issue to insulate only the affected part? What is
getIdreturning on that kind of object?@doctrinebot commented on GitHub (Jul 16, 2013):
Comment created by entering:
Marco I will try to do better, I will try to do make a test case that proves this.
But i can leave here already more info:
@doctrinebot commented on GitHub (Jul 16, 2013):
Comment created by @ocramius:
[~entering] is the proxy in a detached state when you do this? What happens if (with an existing identifier) you do following?
var_dump($entityManager->getReference('Timezone', 123)->getId());@doctrinebot commented on GitHub (Jul 16, 2013):
Comment created by entering:
var_dump ( $this->timezoneRepository->getEM()->getReference('EBCoreKernelBundle:Common\Timezone', 1)->getId() ); // 1Marco yes is on detached mode, and I know that, I'm relying on the proxy to get the ID, because I don't want any queries being "issued", so I'm doing like
$campaign = $campaignRepository->findReadOnly(10); // hit cache$timezoneRepository->findReadOnly($campaign->getTimezone()->getId() /** rely on proxy **/); // hit memcacheThis just work in the last versions of Doctrine that have lazy getId(), but it looks that for traits something wrong happens on the generation of Proxy.
If on Entity timezone I use the trait but override the getId() everything works perfect again.
@doctrinebot commented on GitHub (Jul 16, 2013):
Comment created by @ocramius:
[~entering] does this also happen with 2.3.x? (asking because the proxy generation logic was rewritten for 2.4)
@doctrinebot commented on GitHub (Jul 16, 2013):
Comment created by entering:
2.3 the proxy is quite different but the essence of the problem remains:
Proxy with trait (doesn't work, because as far as I know will try to make a query in detach mode):
Proxy without trait (works well):
@doctrinebot commented on GitHub (Jul 16, 2013):
Comment created by @ocramius:
Ok, so at least I now know it's not an issue with the upgrade, but it was also borked before. Thanks for following along till here: I'll work on a patch as soon as I have time.
@doctrinebot commented on GitHub (Feb 23, 2015):
Comment created by tPl0ch:
@ocramius
This just got a little bit hotter for us. We moved all our ID related code into a trait that is shared by most our entities. After deploying that we saw a dramatic rise in small id based queries to the database, which is related to this bug here.
We had to revert the changes for now, but I'd be happy to work on a fix if there still is a need.
Regards
Thomas
@doctrinebot commented on GitHub (Feb 23, 2015):
Comment created by tPl0ch:
See http://www.doctrine-project.org/jira/browse/DCOM-276
@Jalle19 commented on GitHub (Dec 4, 2018):
The root cause seems to be that
isShortIdentifierGetter()attempts to find the part of the source code where the getter is defined, then it tries to match the code snippet against a regular expression, and if there is a match the method returns true. The problem when traits are used is that the code snippet is the relevant source lines from the class that uses the trait, not the trait itself, hence the check fails and the getter is not eligible for proxying without lazy-loading.@Ocramius commented on GitHub (Dec 4, 2018):
Likely fixed by https://github.com/doctrine/common/pull/861
@Ocramius commented on GitHub (Dec 4, 2018):
Will be handled by
doctrine/common:1.11.0