Open Seldaek opened 10 years ago
Is there already a solution for this issue? I think it's a general problem if a field, which is part of the id, doesn't contain a simple type but a reference to another entity. During serialization the getIdentifier
method calls getIdentifierValues
on the class. Here only the proxy objects are returned and these objects are serialized. During this the real id of reference is lost. Maybe there could be a check if the identifiers array contains a Proxy instance like this:
if ( ! $uow->isInIdentityMap($reference)) {
$class = $this->manager->getClassMetadata(get_class($reference));
$values = $class->getIdentifierValues($reference);
foreach ($values as $key => $value) {
if($value instanceof Proxy) {
$proxyIdentifier = $this->getIdentifier($value, $uow);
//only a single id is accepted.
$values[$key] = $proxyIdentifier[array_keys($proxyIdentifier)[0]];
}
}
return $values;
}
This works for me.
Is there any progress on the issue?
+1
+1, March 2018 and still having this problem. We can't use the ORM as intended now because tests fail upon loading fixtures.
@JustBlackBird @vviippola @paulinevos please help out on https://github.com/doctrine/data-fixtures/pull/167
I have a class that has two identifier fields (a numeric id and a user ManyToOne) so that every user has their own sequence of numeric ids. This causes failures together with the liip functional test bundle when reloading a sqlite DB from cache I believe.
Here is a stack trace:
The ProxyReferenceRepository's serialize and unserialize methods don't deal with non-numeric ids it seems.
Relates to https://github.com/doctrine/data-fixtures/commit/8ffac1c63f34124f693b93889fa32f4036eb241b kinda.
If I dump the $proxyReference at line 91 it is like this:
/cc @guilhermeblanco