-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Adding ORM\JoinTable
attribute to the make:entity
command's ManyToMany
field type
#1416
Open
ramity
wants to merge
6
commits into
symfony:main
Choose a base branch
from
ramity:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d10e50c
Added a prompt if the user would like to specify a joinTable name dur…
ramity 309bf05
fixed the two php-cs-fixer errors
ramity 17b939d
fixed 3 places where ManyToMany relations were being tested
ramity 5abc8c2
updated tests comments to match others, added testcase for custom joi…
ramity f4eda5a
fixed test name + added suggested change to add type to EntityRelatio…
ramity b5b7ccf
initialized value to null to avoid errors from uninit access
ramity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -619,6 +619,20 @@ function ($name) use ($targetClass) { | |
$relation->setMapInverseRelation($mapInverse); | ||
}; | ||
|
||
$askJoinTableName = function (EntityRelation $relation) use ($io) { | ||
$joinTableDecision = $io->confirm( | ||
'Do you want to specify a join table? You may want to do this if you plan on having multiple many-to-many relations to the same entity.', | ||
false | ||
); | ||
|
||
if ($joinTableDecision) { | ||
$relation->setJoinTableName($io->ask( | ||
'What should the join table be named?', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open to suggestions on rewording |
||
lcfirst(Str::getShortClassName($relation->getOwningClass())).ucfirst($relation->getOwningProperty()) | ||
)); | ||
} | ||
}; | ||
|
||
switch ($type) { | ||
case EntityRelation::MANY_TO_ONE: | ||
$relation = new EntityRelation( | ||
|
@@ -708,6 +722,8 @@ function ($name) use ($targetClass) { | |
)); | ||
} | ||
|
||
$askJoinTableName($relation); | ||
|
||
break; | ||
case EntityRelation::ONE_TO_ONE: | ||
$relation = new EntityRelation( | ||
|
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
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
Oops, something went wrong.
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.
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.
Open to suggestions on rewording
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.
In the current placement, this question will be asked for all relation types, right? But we only want it for
ManyToMany
For the wording, what about just one question:
If they hit enter (leave it blank), then we know to name it automatically.
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 area just defines and stores the function as a variable. The logic within isn't actually ran until the
$askJoinTableName($relation);
statement is executed later down in the code here.As much as I'd prefer the lower complexity of one question, we'll want to give the user the ability to say no to the addition of a join table. Cases like bidirectional many-to-many and self referencing many-to-many require the use of a ManyToMany attribute without a JoinTable attribute on one side.