Skip to content

Commit

Permalink
Temporary workaround for doctrine#5988
Browse files Browse the repository at this point in the history
(cherry picked from commit 92e0e29)
  • Loading branch information
fred-jan committed Aug 23, 2016
1 parent aa58203 commit 5f4a11d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Doctrine\DBAL\Types\Type;

use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Utility\PersisterHelper;

/**
Expand Down Expand Up @@ -281,8 +282,26 @@ public function delete($entity)
if ($this->platform->supportsForeignKeyConstraints()) {
$rootClass = $this->em->getClassMetadata($this->class->rootEntityName);
$rootTable = $this->quoteStrategy->getTableName($rootClass, $this->platform);
$types = array_map(function ($identifier) use ($rootClass) {
if (isset($rootClass->fieldMappings[$identifier])) {
return $rootClass->fieldMappings[$identifier]['type'];
}

$targetMapping = $this->em->getClassMetadata($rootClass->associationMappings[$identifier]['targetEntity']);

if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) {
return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type'];
}

if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) {
return $targetMapping->associationMappings[$targetMapping->identifier[0]]['type'];
}

throw ORMException::unrecognizedField($targetMapping->identifier[0]);

}, $rootClass->identifier);

return (bool) $this->conn->delete($rootTable, $id);
return (bool) $this->conn->delete($rootTable, $id, $types);
}

// Delete from all tables individually, starting from this class' table up to the root table.
Expand Down

0 comments on commit 5f4a11d

Please sign in to comment.