-
-
Notifications
You must be signed in to change notification settings - Fork 437
Fix self-referencing entity associations #278
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
Conversation
weaverryan
left a comment
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.
Thanks for taking on this old bug! Great work with the code & test - just a few minor comments :)
src/Maker/MakeEntity.php
Outdated
| $newFieldName = $newField->getOwningProperty(); | ||
| $otherManipulatorFilename = $this->getPathOfClass($newField->getInverseClass()); | ||
| $otherManipulator = $this->createClassManipulator($otherManipulatorFilename, $io, $overwrite); | ||
| if ($newField->getInverseClass() !== $newField->getOwningClass()) { |
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.
Could we use some $newField->isSelfReferencingMethod() here?
src/Util/ClassSourceManipulator.php
Outdated
| private function addCollectionRelation(BaseCollectionRelation $relation) | ||
| { | ||
| $typeHint = $this->addUseStatementIfNecessary($relation->getTargetClassName()); | ||
| $typeHint = !$relation->isSelfReferencing() ? $this->addUseStatementIfNecessary($relation->getTargetClassName()) : 'self'; |
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.
Hmm, maybe reverse this - I think the ! is a bit confusing:
$typeHint = $relation->isSelfReferencing() ? 'self' : $this->addUseStatementIfNecessary($relation->getTargetClassName());
tests/Maker/FunctionalTest.php
Outdated
| // do you want to generate an inverse relation? (default to yes) | ||
| '', | ||
| // field name on opposite side | ||
| 'wards', |
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.
This word isn't commonly used in English. Using dependents might be better (A parent/guardian refers to their children as "dependents")
|
Thank you @codedmonkey! |
Fixes faulty generation of entities with self-referencing associations #166. It looks like changes for the owning entity were overwritten by the changes for the inversed entity.