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

[Doctrine Bridge] fix UniqueEntityValidator for composite object primary keys #21288

Merged
merged 2 commits into from Jan 16, 2017

Conversation

dmaicher
Copy link
Contributor

@dmaicher dmaicher commented Jan 14, 2017

Q A
Branch? master / 3.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes (fail on php 7.1 unrelated?)
Fixed tickets #21274
License MIT
Doc PR -

This PR fixes an issue with the UniqueEntityValidator in case the entity being validated uses a composite primary key via relations to other entities whose classes do not have a __toString method.

$identifiers = array_map(function ($identifier) use ($em) {
// identifiers can be objects (without any __toString method) if its a composite PK
if (is_object($identifier) && !method_exists($identifier, '__toString')) {
return sprintf('(%s)', $this->buildInvalidValueString($em, $em->getClassMetadata(get_class($identifier)), $identifier));
Copy link
Contributor Author

@dmaicher dmaicher Jan 14, 2017

Choose a reason for hiding this comment

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

is it safe to use the same object manager here for the related class? Not sure if Doctrine supports relations between classes of different object managers?


$this->validator->validate($newEntity, $constraint);

$expectedValue = 'Object of class "Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeObjectNoToStringIdEntity" identified by "(Object of class "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity" identified by "1"), (Object of class "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity" identified by "2")"';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we find a shorter way to build this message? 😝

@dmaicher
Copy link
Contributor Author

@HeahDude as you added this code (40c0c52) what do you think about this?

@HeahDude
Copy link
Contributor

I've discussed this PR with @dmaicher in dmaicher#1, which is now merged.

This looks good to me.

ping @symfony/deciders

@nicolas-grekas nicolas-grekas changed the title [Doctrine Bridge] fix UniqueEntityValidator for composite object prim… [Doctrine Bridge] fix UniqueEntityValidator for composite object primary keys Jan 16, 2017
@nicolas-grekas
Copy link
Member

Failure looks related to me (not the messages about getMock, but the one about CompositeObjectNoToStringIdEntity) - maybe a composer.json update needed somewhere?

@HeahDude
Copy link
Contributor

@nicolas-grekas I've opened dmaicher#2 which seems to have fixed the tests, waiting for @dmaicher to merge it.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 16, 2017

@dmaicher can you please squash the history? We can't merge (nor don't want to :) ) merge PRs with merges inside.

@nicolas-grekas
Copy link
Member

(maybe keep just two commits, one for you and one for @HeahDude with rebase -i ?)

@dmaicher
Copy link
Contributor Author

@nicolas-grekas sure 😉 Let's wait for the build and hope its fixed

@HeahDude
Copy link
Contributor

Green 🎉

@dmaicher
Copy link
Contributor Author

Done 😉

@fabpot
Copy link
Member

fabpot commented Jan 16, 2017

I've not checked, but don't we have the same issue in 2.7 and 2.8?

@HeahDude
Copy link
Contributor

@fabpot This fix is related to a feature introduced in 3.1 #15279, and not enough fixed by #19227 (missing composite identifiers handling, provided here).

@fabpot
Copy link
Member

fabpot commented Jan 16, 2017

Thank you @dmaicher.

@fabpot fabpot merged commit b3ced86 into symfony:3.1 Jan 16, 2017
fabpot added a commit that referenced this pull request Jan 16, 2017
…object primary keys (dmaicher, HeahDude)

This PR was merged into the 3.1 branch.

Discussion
----------

[Doctrine Bridge] fix UniqueEntityValidator for composite object primary keys

| Q             | A
| ------------- | ---
| Branch?       | master / 3.1
| Bug fix?      | yes
| New feature?  |no
| BC breaks?    | no
| Deprecations? |no
| Tests pass?   | yes (fail on php 7.1 unrelated?)
| Fixed tickets | #21274
| License       | MIT
| Doc PR        | -

This PR fixes an issue with the UniqueEntityValidator in case the entity being validated uses a composite primary key via relations to other entities whose classes do not have a `__toString` method.

Commits
-------

b3ced86 [DoctrineBridge] Fixed invalid unique value as composite key
5aadce3 [Doctrine Bridge] fix UniqueEntityValidator for composite object primary keys
@fabpot fabpot mentioned this pull request Jan 28, 2017
@fabpot fabpot mentioned this pull request Feb 6, 2017
@dmaicher dmaicher deleted the unique-entity-pk-objects branch August 23, 2018 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants