You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Therefore, it crashes when the returned identifiers are objects (associated entities).
Details
When the DoctrineBridge UniqueEntityValidator encounters a non unique value, it builds a constraint violation with it. In case this value is not castable to a string it tries to build one itself:
if (is_object($invalidValue) && !method_exists($invalidValue, '__toString')) {
$invalidValue = sprintf('Object of class "%s" identified by "%s"', get_class($entity), implode(', ', $class->getIdentifierValues($entity)));
}
If the entity's identifiers are associations (for example a Friendship entity with the two users as composite PK), $class->getIdentifierValues($entity) returns those entities. If they don't have any __toString() method either, the implode() function can't execute and it errors out with the following message:
Error: Object of class [...] could not be converted to string
Not sure what the complete value should be anyway. Recursing one level would produce a rather convoluted string...:
Object of class Acme\AppBundle\Entity\Friendship identified by object of class Acme\AppBundle\Entity\User identified by 123, object of class Acme\AppBundle\Entity\User identified by 456
The text was updated successfully, but these errors were encountered:
…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
Uh oh!
There was an error while loading. Please reload this page.
tl;dr
The UniqueEntityValidator makes the wrong assumption that Doctrine's
ClassMetaData::getIdentifierValues()
can only return scalars:Therefore, it crashes when the returned identifiers are objects (associated entities).
Details
When the DoctrineBridge UniqueEntityValidator encounters a non unique value, it builds a constraint violation with it. In case this value is not castable to a string it tries to build one itself:
If the entity's identifiers are associations (for example a Friendship entity with the two users as composite PK),
$class->getIdentifierValues($entity)
returns those entities. If they don't have any__toString()
method either, theimplode()
function can't execute and it errors out with the following message:Not sure what the complete value should be anyway. Recursing one level would produce a rather convoluted string...:
The text was updated successfully, but these errors were encountered: