-
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
Fix for bug #8229 (id column from parent class renamed in child class) #8234
Conversation
Please associate your email address with your Github account, or change the Please kindly squash your commits together. If you don't, we'll try to remember to do it for you but it's best if you save us this trouble. How to do that?
|
Done I think. Not sure about the e-mail - I had to convert my account to an organization last week and switched to a new account, but GitHub Desktop didn't update the name/e-mail after switching. PS: Thanks for the rebase instruction. I also had to add |
Just recognized another bug related to this one. The foreign key for the id column in the child table is not set, if it's renamed via AttributeOverride. I think this is an ORM bug, not a migrations problem, right? Will look into it... |
The foreign key generation is also fixed now (the "inherited" property of the column has been set correctly, but accidentally removed later, so that the foreign key was not created). After this I also had to fix the generation of the WHERE condition for the id column (which depends on the "inherited" property). |
@ostrolucky I implemented all suggested changes. |
Just realized an error in the annotations after the last change. Will check that. Sorry. |
I fixed the wrong annotation, and I also added a test for the possible foreign key problem when deleting entries from the tables of a joined inheritance entity. |
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.
Nice work! :) I'm not comfortable to merge this on my own though, let's see if somebody else will pop in. In case nobody will, ping me in a few weeks and we will proceed anyways.
Hmm, there seems to be a problem with Travis CI: Fatal error: Uncaught InvalidArgumentException: Extension class "PhpBench\Extensions\Dbal\DbalExtension" does not exist in phar:///home/travis/build/doctrine/orm/phpbench.phar/vendor/phpbench/container/lib/Container.php:54 |
Blocked by #8252 |
Thanks for looking into the build problem... Latest changes:
|
This fixes problems with id columns defined in the parent class but renamed in the child class using an attribute override. Before this change always the child column name was used (which was not present in the parent class), now the correct column names are used for the parent table when creating inserts, joins and deletions for it.
I just fixed another special case with wrong column names when creating a pessimistic write lock. |
Alright I see still nobody merged this, so let's do it. Thanks for your effort :) |
I just stumbled over this and i am considering to revert this change, because i am unsure about the consequences of such a radical change in a patch version, and because the Java Persistence API doesn't allow AttributeOverride to be used on STI or JTI. I am unsure about the consequences of this change and it should be broader discussed and not be part of a patch release. Unrelated, the change to |
Thanks @beberlei for reviewing this change. Following the Doctrine documentation, the attribute overrides feature can be used to override all attribute settings, explicitly including the name (see the provided example). The feature existed before, but it didnt't work in all cases. So I cannot see a behavior change here, but a bugfix. I checked the change in JoinedSubclassPersister::delete() again and I will try to explain it: Before:
After:
So IMHO it's also just a bugfix and no behavior change, BUT I think, that this can be improved, because I missed another potential bug (which also existed before): So I'd suggest to fix this as follows: |
@cziegenberg ah thanks for linking the documentation it actually says this is only working with mapped superclasses:
As for the JTI and delete. It was the previous behavior that a foreign key with delete cascade had to be configured. For 10 years I cannot remember a single discussion or bug related to people expecting this to work different. Your approach is a bit safer, but its also inefficient, because it can potentially lead to increase number of DELETE statements. |
@beberlei Regarding the JTI and attribute overrides. Okay, the documentation only mentiones the mapped superclass, but I only read this as the typical example. And attribute overrides have also been processed for JTI before, they worked, except for identifiers. |
Documentation also provides example where attribute overrides are used without mapped superclass https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/tutorials/override-field-association-mappings-in-subclasses.html |
Just to clarify, this documentation example is for a trait, which is copied into the same entity, so it is not using inheritance either. @cziegenberg Attribute overrides for regular field mappings in JTI are broken though. You cannot query these fields across the class structure anymore and if the column is not nullable on the parent class, then it breaks during inserting. "It works" for me just means it accidently does what it should in 50% of the use cases, but we forgot to prevent it. |
I think what @ostrolucky wanted to say is that a mapped superclass isn't always required, while you said it's "only working with mapped superclasses". This doesn't mean other types of inheritance were planned to be supported, but that the documentation isn't that clear. I also misunderstood the documentation, and yes, it worked for me (after the fix) and it passed all tests (also for other use cases), so from my point of view everything was fine. You have an overview of all the use cases and features you want to support. If you say it's too risky or causes problems with other use cases that cannot be fixed, then you have to revert the changes (and prevent the wrong usage of this feature). I have to accept this. |
* [GH-8229] Prevent AttributeOverride on fields from entities, only allowed for MappedSuperclass * [GH-8229] Prevent AssociationOverride on fields from entities, only allowed for MappedSuperclass * Revert "Fix SQL alias generation regression for simple inheritance (#8329)" This reverts commit f4ebded. * [GH-8229] Finalize checks for illegal attribute/assocation overrides. * [GH-8229] Revert ccae8f7 PR #8234 * [GH-8229] Update documentation to clarify only mapped superclass or trait works with overrides * [GH-8229] Fix style violations introduced by revert * [GH-8229] Fix style violations introduced by revert * [GH-8229] Temporarily disable the exception until 2.8. * Make phpcs happy
This fixes problems with id columns defined in the parent class but renamed in the child class using an attribute override. Before this change always the child column name was used (which was not present in the parent class), now the correct column names are used for the parent table when creating inserts, joins and deletions for it.