-
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
Extract mappings to their own DTOs #10405
Conversation
What is the supposed migration path for this? In 2.x, the I don't know about the deprecation/transition rules for this project. But changing this on the 3.0 branch means things will break during the upgrade, and there is no "smooth" transition (e. g. by getting deprecation warnings in 2.x, which can be fixed, then the 3.0 upgrade can be made). I generally support the idea and think it's a good thing design-wise. Can we make that more user-friendly, by
|
I'd actually add the array access on 3.0,much like what I did recently for the Token class in doctrine/lexer, that way the type does not change from array to DTO in a minor. What we might do to ease the transition could be to introduce a factory that would produce arrays with nullable properties instead of optional properties, to make the array closer to the final dto |
/** @var int|null The database length of the column. Optional. Default value taken from the type. */ | ||
public int|null $length = null; | ||
/** | ||
* @var bool|null Marks the field as the primary key of the entity. Multiple |
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.
While trying to fix the build, I reverted to bool|null
here, to be closer to the previous situation. Now that the build is green, I can do a separate commit to make boolean field not-nullable, and default to false
.
@@ -328,15 +328,16 @@ private function getShortName(string $className): string | |||
private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass): void | |||
{ | |||
foreach ($parentClass->fieldMappings as $mapping) { | |||
if (! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) { | |||
$mapping['inherited'] = $parentClass->name; | |||
$subClassMapping = clone $mapping; |
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.
Lost a huge amount of time on this, but yeah, we have to clone here now.
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.
#10397 changed that area, did you include/merge that already?
why can’t you just update the value?
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 need to update the child value without updating the parent value. When using an array, a copy is made. When using objects, we're altering the parent objects.
We do need to do a merge up.
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.
Would it be better to do the clone up in doLoadMetadata
or so, in a more central location?
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.
Merge up done in #10421
About doLoadMetadata
, I'm not sure… I mean there's one clone per mapping to do, so it's not like you could pass clones to addInheritedFields
or something 🤔
Did a new push, comes with static analysis issues that I should be able to solve once I have converted every argument to |
Pushed a new version with an association mapping DTO, hopefully that was the hardest part of the job. |
5ab67bc
to
c92ad09
Compare
Just found out that I'm doing the opposite of what's been done 13 years ago in 8d3e0e6 😅 |
Maybe performance? Arrays might be faster to access than methods to call? |
Discussed it internally, and you are right… well, you were. It was true in PHP 5.3, but no longer is. I think I can proceed with this. |
Before you put too much work into it, are you sure there is a smooth migration path? |
I think the |
8296190
to
6974d9c
Compare
Instead of synchronizing isCascade* with cascade, we dynamically compute these methods.
Now that we deal with objects, everything is simpler.
When switching to an object API, it becomes obvious that it should be mandatory. You have to assert it is not null everywhere.
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 haven't done the full review yet. The amount of changes slows my progress, so maybe I'll do it in parts.
@@ -157,7 +158,7 @@ public function evictCollectionRegions(): void | |||
|
|||
foreach ($metadatas as $metadata) { | |||
foreach ($metadata->associationMappings as $association) { | |||
if (! $association['type'] & ClassMetadata::TO_MANY) { | |||
if (! $association instanceof ToManyAssociationMapping) { |
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.
If those are all AssociationMapping
, wouldn't the use of a method be an option instead of an instanceof
check? You've used methods at other places too.
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.
You're right, I will add such a method.
Closing in favor of smaller PRs, the first of which will be #10607 |
An experiment, not sure if I will manage to do it, but at least it will allow us to port some changes to 2.x:
FieldMapping
the DTO is used,FieldMapping
the array-shape should be usedFieldMapping
(for instance,version
, ordefault
)Todo
__sleep()
isCascade*
properties