Com base na resposta daqui:Como configurar a tabela prefixo no symfony2
-
Abra Resources/config/services.yml do seu pacote e adicione:
parameters: mybundle.db.sequence_prefix: myprefix_
-
Adicionar um novo serviço:
services: mybundle.sqprefix_subscriber: class: MyBundle\Subscriber\SequencePrefixSubscriber arguments: [%mybundle.db.sequence_prefix%] tags: - { name: doctrine.event_subscriber }
-
Criar MyBundle\Subscriber\SequencePrefixSubscriber.php
<?php namespace MyBundle\Subscriber; use Doctrine\ORM\Event\LoadClassMetadataEventArgs; class SequencePrefixSubscriber implements \Doctrine\Common\EventSubscriber { protected $prefix = ''; public function __construct($prefix) { $this->prefix = (string) $prefix; } public function getSubscribedEvents() { return array('loadClassMetadata'); } public function loadClassMetadata(LoadClassMetadataEventArgs $args) { $classMetadata = $args->getClassMetadata(); if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) { return; } if ($classMetadata->isIdGeneratorSequence()) { $newDefinition = $classMetadata->sequenceGeneratorDefinition; $newDefinition['sequenceName'] = $this->prefix . $newDefinition['sequenceName']; $classMetadata->setSequenceGeneratorDefinition($newDefinition); $em = $args->getEntityManager(); if (isset($classMetadata->idGenerator)) { $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator( $em->getConfiguration()->getQuoteStrategy()->getSequenceName( $newDefinition, $classMetadata, $em->getConnection()->getDatabasePlatform()), $newDefinition['allocationSize'] ); $classMetadata->setIdGenerator($sequenceGenerator); } } } }
Referência:http://www .doctrine-project.org/api/orm/2.0/class-Doctrine.ORM.Mapping.ClassMetadataInfo.html
A documentação diz
READ-ONLY
para a sequenceGeneratorDefinition
então eu acho que é mais limpo usar o setter do que alterar o valor manualmente (mas não há getter, então usamos apenas o valor da propriedade pública).