Skip to content

Instantly share code, notes, and snippets.

@enumag
Created October 14, 2018 20:41
Show Gist options
  • Save enumag/22c14d6a7bf55cf390ed44fd33dbd584 to your computer and use it in GitHub Desktop.
Save enumag/22c14d6a7bf55cf390ed44fd33dbd584 to your computer and use it in GitHub Desktop.
DeferredExplicitTrackingPolicySubscriber
<?php declare(strict_types = 1);
namespace App\Library\Doctrine\Subscriber;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadata;
final class DeferredExplicitTrackingPolicySubscriber implements EventSubscriber
{
/**
* @return string[]
*/
public function getSubscribedEvents(): array
{
return [
Events::loadClassMetadata,
];
}
public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
{
$metadata = $event->getClassMetadata();
$metadata->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment