Skip to content

Commit

Permalink
Adopt @cevou's solution from #135
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Mar 26, 2015
1 parent 9c33b16 commit 6367b08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function serialize()
$simpleReferences = array();

foreach ($this->getReferences() as $name => $reference) {
$reference = $this->getReference($name);
$className = $this->getRealClass(get_class($reference));

$simpleReferences[$name] = array($className, $this->getIdentifier($reference, $unitOfWork));
Expand Down
17 changes: 15 additions & 2 deletions lib/Doctrine/Common/DataFixtures/ReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\Common\DataFixtures;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\Proxy;

/**
* ReferenceRepository class manages references for
Expand Down Expand Up @@ -77,8 +78,20 @@ protected function getIdentifier($reference, $uow)
// In case Reference is not yet managed in UnitOfWork
if ( ! $uow->isInIdentityMap($reference)) {
$class = $this->manager->getClassMetadata(get_class($reference));

return $class->getIdentifierValues($reference);

$values = $class->getIdentifierValues($reference);

// See https://github.com/doctrine/data-fixtures/issues/135 and
// https://github.com/doctrine/data-fixtures/issues/167
foreach ($values as $key => $value) {
if (!is_scalar($value)) { // or: is_object?
$proxyId = $this->getIdentifier($value, $uow);
$keys = array_keys($proxyId);
$values[$key] = $proxyId[$keys[0]];
}
}

return $values;
}

// Dealing with ORM UnitOfWork
Expand Down

0 comments on commit 6367b08

Please # to comment.