-
-
Notifications
You must be signed in to change notification settings - Fork 515
Skip native lazy object initialization for unmapped properties #2922
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
base: 2.15.x
Are you sure you want to change the base?
Conversation
65b9940 to
b4022ab
Compare
| { | ||
| if (isset($this->skippedProperties[$metadata->name])) { | ||
| return $this->skippedProperties[$metadata->name]; | ||
| } |
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.
Memoization!
| continue; | ||
| } | ||
|
|
||
| if ($property->isVirtual()) { |
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'm pleasantly surprised that the ReflectionProperty docs explain what virtual properties are.
| $skippedProperties = []; | ||
| foreach ($metadata->reflClass->getProperties() as $property) { | ||
| if (array_key_exists($property->name, $metadata->propertyAccessors)) { | ||
| continue; |
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.
Just to confirm, every mapped field should have its own property accessor according to ClassMetadata::mapField(), correct?
So this foreach look is really just checking for unmapped, non-virtual properties.
Will this logic be useful in any other contexts? If so, it may be worth capturing this logic in a ClassMetadata method.
Summary
Re-implement #2698 for native lazy objects.
Using the method
ReflectionProperty::skipLazyInitialization, accessing properties that are not mapped in Doctrine will not initialize the document object.