-
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
EntityManager::getReference() should handle a PK which is also a FK #11601
base: 2.20.x
Are you sure you want to change the base?
Conversation
It seems there are CI jobs failing. Please take a look at this guide for more on how to handle those. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this proposed change is of any interest I will improve it and deduplicate this code in a second version.
I see no reason to reject your change, so I'd say please go ahead and deduplicate this.
If this also affects 2.x, please retarget. |
d29511b
to
9dbc430
Compare
Does this need to be a draft? It looks like it's reviewable to me as a regular PR. Or is this still a WIP? |
9dbc430
to
b2e4500
Compare
Yes, I am still working on it. I duplicated some code for the proof of concept, this needs refactoring. In the meantime, I discovered that error cases also need to be addressed (tests marked as skipped with "work in progress"). Additionally, I discovered that updating the identifier of a proxy fails silently. This is pre-existing behaviour, but the change I propose introduces a whole class of scenarios (tests skipped with "use case needs to be confirmed") that I think should be addressed. I wanted to open a discussion about it, please let me know if I should open another issue instead. Notice that all skipped tests pass if one replaces For information, I probably won't be able to work on it much before next week-end. |
Apologies for the delay, I've been quite busy lately. I should be able to submit a final proposal by the end of the weekend. |
b2e4500
to
6ae5153
Compare
I'm afraid I am unable to address either case:
I am not sure as how to move forward, please advise:
|
5c7ced1
to
be06aa9
Compare
if ($this->_em->getConfiguration()->isLazyGhostObjectEnabled()) { | ||
self::assertInstanceOf(UserProxy::class, $profile->user); | ||
self::assertEquals('Athos', $profile->user->name); | ||
} else { | ||
if (PHP_VERSION_ID >= 80100) { | ||
$this->markTestIncomplete(); | ||
} | ||
self::assertEquals(1, $profile->user); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out that Proxies behave slightly differently when "Lazy Ghost Objects" are not enabled. Through experimentation I reached the conclusion that only PHP < 8.1 appears to be displaying the legacy behaviour. This deprecation notice seems to confirm my hypothesis.
I now realize I quite grossly underestimated the beast. I will not be able, nor willing, to dig deeper into this. |
EntityManager::getReference()
should be able to handle a PK which is also a FK, just the way::find()
already does.Current behaviour:
With this PR, the proxy factory would hydrate the proxy with a reference to the related entity if a relation is detected (addressing case 1 above)
Additionally
EntityManager::getReference()
would use the same approach as infind()
and attempt to extract the underlying PK value when passed an entity (case 2).In this first attempt, I just copy/pasted some code from
find()
togetReference()
. These two have a lot in common, if this proposed change is of any interest I will improve it and deduplicate this code in a second version.P.S. I believe this (somewhat related) issue #5640 may be closed.