Skip to content
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

Merged
merged 7 commits into from Jul 22, 2017
Merged

#5804 Versioning doesn't work with a custom type primary key #6485

merged 7 commits into from Jul 22, 2017

Conversation

alle
Copy link

@alle alle commented Jun 5, 2017

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.

@ngrevet
Copy link

ngrevet commented Jun 5, 2017

Thanks for taking the time to work my code into a PR, I'm not well versed in PRs on open source projects.

Copy link
Member

@Ocramius Ocramius left a 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

@alle
Copy link
Author

alle commented Jun 6, 2017

@Ocramius @ngrevet-lightspeed Everything should be fine, now. I was too hurried, last time. Sorry.

@Ocramius
Copy link
Member

Ocramius commented Jun 6, 2017

@alle I still don't see test changes though :-\

@alle
Copy link
Author

alle commented Jun 6, 2017

@Ocramius Well, I thought tests shouldn't change, should they?
I thought I fixed this bug, working on the BasicEntityPersister::fetchVersionValue() method, by passing the involved tests, without changing them. Humbly, am I missing something?

@Ocramius
Copy link
Member

Ocramius commented Jun 6, 2017

@alle a test demonstrating the original bug (failing with the original repository state, passing with this patch) is needed ;-)

@alle
Copy link
Author

alle commented Jun 12, 2017

@Ocramius: @astepin did the job (in #6496) that I should have done from myself.
@astepin The only change I made is in the custom type getSQLDeclaration() method: your PR was failing against the Postgres platform, since Doctrine maps to a specific datatype for GUIDs on that platform.

@alle
Copy link
Author

alle commented Jun 14, 2017

I changed the involved classes in tests, complying to other tests' structure, in order to avoid a merge conflict on the SchemaValidatorTest, due to recent updates.

@@ -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) {
Copy link
Member

@lcobucci lcobucci Jun 20, 2017

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));
}

Copy link
Author

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.

@alle
Copy link
Author

alle commented Jul 6, 2017

@Ocramius @lcobucci Is there any possibility to have this PR merged? I didn't see any news since the last changes.

* @Column(type="GH5804Type")
* @GeneratedValue(strategy="CUSTOM")
* @CustomIdGenerator(class="\Doctrine\Tests\Models\GH5804\GH5804Generator")
")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax error ;)

Copy link
Author

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")
Copy link
Member

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

Copy link
Author

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?

Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

@alcaeus alcaeus Jul 6, 2017

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.

Copy link
Member

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 😉

@lcobucci lcobucci self-assigned this Jul 22, 2017
@lcobucci
Copy link
Member

I'll take a look at this in a bit

@lcobucci
Copy link
Member

@alle thanks for your contribution, I've simplified things a bit (kept all test related classes together).

@Ocramius it LGTM, can you check this one to see if we're good to go?

@Ocramius Ocramius changed the title Fixes #5804 #5804 Versioning doesn't work with a custom type primary key Jul 22, 2017
@Ocramius Ocramius added this to the 2.6.0 milestone Jul 22, 2017
Copy link
Member

@Ocramius Ocramius left a 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 = [];
Copy link
Member

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;
/**
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really needed

@lcobucci lcobucci merged commit 9826d9c into doctrine:master Jul 22, 2017
@lcobucci
Copy link
Member

@alle 🚢 thanks!

@alle
Copy link
Author

alle commented Jul 24, 2017

Thank you so much, guys!
This was my first opportunity to contribute to this project, even to "calibrate" myself to future contributions. Or at least I hope so!

@alle alle deleted the versionWithCustomTypePrimaryKey branch July 24, 2017 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Versioning doesn't work with a custom type primary key
5 participants