-
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
#5804 Versioning doesn't work with a custom type primary key #6485
Conversation
Thanks for taking the time to work my code into a PR, I'm not well versed in PRs on open source projects. |
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.
@alle the patch needs tests to be validated
@Ocramius @ngrevet-lightspeed Everything should be fine, now. I was too hurried, last time. Sorry. |
@alle I still don't see test changes though :-\ |
@Ocramius Well, I thought tests shouldn't change, should they? |
@alle a test demonstrating the original bug (failing with the original repository state, passing with this patch) is needed ;-) |
I changed the involved classes in tests, complying to other tests' structure, in order to avoid a merge conflict on the |
@@ -344,9 +344,16 @@ protected function fetchVersionValue($versionedClass, array $id) | |||
. ' FROM ' . $tableName | |||
. ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; | |||
|
|||
$types = []; | |||
foreach ($id as $field => $value) { | |||
foreach ($this->getTypes($field, $value, $versionedClass) as $type) { |
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.
Do we need to iterate this too? I mean, in theory we could use array_merge()
right, like:
$types = [];
foreach ($id as $field => $value) {
$types = array_merge($types, $this->getTypes($field, $value, $versionedClass));
}
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.
@lcobucci You're simply right.
* @Column(type="GH5804Type") | ||
* @GeneratedValue(strategy="CUSTOM") | ||
* @CustomIdGenerator(class="\Doctrine\Tests\Models\GH5804\GH5804Generator") | ||
") |
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.
Syntax error ;)
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.
Aaargh! Didn't see that!
* @Id | ||
* @Column(type="GH5804Type") | ||
* @GeneratedValue(strategy="CUSTOM") | ||
* @CustomIdGenerator(class="\Doctrine\Tests\Models\GH5804\GH5804Generator") |
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/Should use ::class
constant
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 which form? Any example?
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.
Paired with a use
statement: @CustomIdGenerator(class=GH5804Generator::class)
. Works with Annotations >= 1.2 IIRC.
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 guessed it was that way, but my local tests fail. I even update merged with the latest master
release, updated the dependencies (my Annotations version was right, anyway), but your suggestion (which seems to be logical) doesn't work to me. Did you try by yourself?
Anyway, even without that ::class
notation, everything is fine.
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.
That's strange. I've been using that for (what feels like) a couple of years 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.
It requires the FQCN, just that 😉
I'll take a look at this in a bit |
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.
Some nitpicks apply
@@ -344,9 +344,14 @@ protected function fetchVersionValue($versionedClass, array $id) | |||
. ' FROM ' . $tableName | |||
. ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; | |||
|
|||
$types = []; |
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.
Can this block be moved to a private method?
* @CustomIdGenerator(class=\Doctrine\Tests\ORM\Functional\Ticket\GH5804Generator::class) | ||
*/ | ||
public $id; | ||
/** |
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.
Spacing
|
||
/** | ||
* @Entity | ||
* @Table(name="gh5804_articles") |
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.
Not really needed
@alle 🚢 thanks! |
Thank you so much, guys! |
This PR fixes #5804.
It's not a my own solution, but the one provided by @ngrevet-lightspeed.
Since I need this fixed, I made this PR on behalf of @ngrevet-lightspeed.