-
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
Put up a warning sign that mapping may not be inherited from transient classes #10392
Merged
SenseException
merged 2 commits into
doctrine:2.14.x
from
mpdude:warning-unmapped-classes
Feb 8, 2023
Merged
Put up a warning sign that mapping may not be inherited from transient classes #10392
SenseException
merged 2 commits into
doctrine:2.14.x
from
mpdude:warning-unmapped-classes
Feb 8, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mpdude
force-pushed
the
warning-unmapped-classes
branch
from
January 13, 2023 12:52
a15a34d
to
a221168
Compare
…t classes This _seems_ to work, but... To my understanding, that is only because `ReflectionClass::getProperties` will report `protected` properties also for subclasses, including DocBlocks etc. The mapping drivers are unable to tell where a field comes from, so they pick up the mapping and treat it as originating from the inheriting class. If that is indeed outside of what the ORM was designed for (sombody please confirm?), then we should explicitly discourage it. Yes, I have seen examples of this in the wild.
mpdude
force-pushed
the
warning-unmapped-classes
branch
from
January 13, 2023 12:55
a221168
to
0b8254d
Compare
greg0ire
approved these changes
Feb 5, 2023
SenseException
approved these changes
Feb 8, 2023
Gwemox
pushed a commit
to Gwemox/orm
that referenced
this pull request
Feb 10, 2023
…t classes (doctrine#10392) This _seems_ to work, but... To my understanding, that is only because `ReflectionClass::getProperties` will report `protected` properties also for subclasses, including DocBlocks etc. The mapping drivers are unable to tell where a field comes from, so they pick up the mapping and treat it as originating from the inheriting class. If that is indeed outside of what the ORM was designed for (sombody please confirm?), then we should explicitly discourage it. Yes, I have seen examples of this in the wild.
derrabus
added a commit
to derrabus/orm
that referenced
this pull request
Feb 28, 2023
* 2.14.x: Ignore the cache dir of PHPUnit 10 (doctrine#10546) Make data providers static (doctrine#10544) Bump dev tools (doctrine#10541) Mark SqlWalker methods as not deprecated (doctrine#10540) docs: consistency order for docblock in association mapping (doctrine#10534) Correct use of PHP attribute fix typo in faq.rst (doctrine#10526) fix: use executeStatement in SchemaTool (doctrine#10516) Write a test in a more specific way Put up a warning sign that mapping may not be inherited from transient classes (doctrine#10392) Avoid unnecessary information in query hints to improve query cache hit ratio
derrabus
added a commit
that referenced
this pull request
Feb 28, 2023
* 2.14.x: Ignore the cache dir of PHPUnit 10 (#10546) Make data providers static (#10544) Bump dev tools (#10541) Mark SqlWalker methods as not deprecated (#10540) docs: consistency order for docblock in association mapping (#10534) Correct use of PHP attribute fix typo in faq.rst (#10526) fix: use executeStatement in SchemaTool (#10516) Write a test in a more specific way Put up a warning sign that mapping may not be inherited from transient classes (#10392) Avoid unnecessary information in query hints to improve query cache hit ratio
derrabus
added a commit
to derrabus/orm
that referenced
this pull request
Feb 28, 2023
* 2.15.x: Ignore the cache dir of PHPUnit 10 (doctrine#10546) Make data providers static (doctrine#10545) Make data providers static (doctrine#10544) Bump dev tools (doctrine#10541) Mark SqlWalker methods as not deprecated (doctrine#10540) docs: consistency order for docblock in association mapping (doctrine#10534) Correct use of PHP attribute fix typo in faq.rst (doctrine#10526) fix: use executeStatement in SchemaTool (doctrine#10516) Write a test in a more specific way Put up a warning sign that mapping may not be inherited from transient classes (doctrine#10392) Avoid unnecessary information in query hints to improve query cache hit ratio
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This...
... seems to work, since it results in a single
Child
entity class with both fields, and also the$name
field is configured withname="name_override_config"
.The result comes from the (current) annotations/attribute mapping driver implementation: PHP reflection will report
protected
andpublic
properties also for subclasses. Since there is no other entity or mapped superclass aboveChild
in this example, the mapping driver assumes that all fields were declared on theChild
class initially.It will not work for e. g. class-level annotations like
@Table
onParent
, since those are not inherited/reported by the Reflection API for theChild
subclass. Also, it does not work forprivate
properties on theParent
class, since those don't show up in theReflectionClass::getProperties()
return value for theChild
class.We should explicitly warn users that this approach to configuration (and yes, I've seen this in the wild) is beyond what the ORM was designed for.
Note that using traits to horizontally reuse mapped fields is nothing different – it pulls fields into classes, including their attributes and annotations (= docblocks). The PHP Reflection API will report those fields as if they had been declared in the class using the trait. Traits have the extra side effect that
private
fields become part of the class where the trait is used, so they are reported as properties as well.