-
-
Notifications
You must be signed in to change notification settings - Fork 513
Convert the value of the "version" field using its known type #2813
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
@@ -218,7 +218,7 @@ public function executeInserts(array $options = []): void | |||
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion); | |||
} | |||
|
|||
$data[$versionMapping['name']] = $type->convertPHPToDatabaseValue($nextVersion); |
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 is a static method called on the instance. So it was possible to change the behavior for a custom type by overriding the method, but that's not how it's supposed to be used.
In fact, this method should be final
.
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.
Are you suggesting that the convertPHPToDatabaseValue()
should be final
? If so, I agree and we should probably track that with a separate ticket for the next major version.
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.
Yes, that's the idea. But a better approach would be to extract the static methods into a TypeRegistry
, similar to DBAL. #2818
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.
Pull Request Overview
This PR fixes an issue where custom version field types were not being properly converted to database values. Instead of guessing the field type, the code now uses the configured type for the version field to ensure proper conversion.
- Replace static
Type::convertPHPToDatabaseValue()
calls with instance$type->convertToDatabaseValue()
- Add comprehensive test coverage for custom version field types
- Ensure custom types implementing
Versionable
work correctly with version field operations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | Updates version field conversion to use the configured type instead of static type guessing |
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2789Test.php | Adds test case demonstrating custom version field type functionality with Binary storage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
LGTM, but two small suggestions.
@@ -218,7 +218,7 @@ public function executeInserts(array $options = []): void | |||
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion); | |||
} | |||
|
|||
$data[$versionMapping['name']] = $type->convertPHPToDatabaseValue($nextVersion); |
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.
Are you suggesting that the convertPHPToDatabaseValue()
should be final
? If so, I agree and we should probably track that with a separate ticket for the next major version.
Summary
Instead of guessing the type of the version field value in order to convert the value into a MongoDB compatible value, we can use the type that is configured for this field. Otherwise the detection of the field type from the value type fails for custom types.