Dynamiczne nazwy tabel / encji w Doctrine 2

Mam nadzieję, że ktoś może rzucić trochę światła na to, co dzieje się z moim kodem.

Muszę mieć obiekt reprezentujący ogólną tabelę jako model dla tabel z przyrostkiem X id. Na przykład mam obiekt: CustomerX Tabele, które muszę wysłać, to cusotmer_1, customer_2, customer_3 ... etc ..

Obecnie używam:

class CustomerX {
/**
 * CustomerX
 *
 * @Table(name="customer_")
 * @Entity
 */


//..... properties and setters/getters....

private $_tableName = null;

public function getTableName() {
    return $this->_tableName;
}

public function setTableName($tableName) {
    $this->_tableName = $tableName;
    return $this;
}

public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
    $classMetadata = $eventArgs->getClassMetadata();

    $table = $classMetadata->table;
    $table['name'] = 'customer_'.$this->getTableName();
    $classMetadata->setPrimaryTable($table);
}


public static function getCustomerRecords($CustomerId) {
    $em = \Helper_Doctrine::em();

    $custTable = new \ME\CustomerX();
    $custTable->setTableName($CustomerId);
    $evm = $em->getEventManager();
    $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $custTable);

    //get the customer info
    $query = $em->createQuery(
        'SELECT w
         FROM \ME\CustomerX w
         WHERE w.customerId = :CustId';
    $query->setParameter('CustId', $CustomerId);
    $custParams = $query->getResult();

    $evm->removeEventListener(\Doctrine\ORM\Events::loadClassMetadata, $custTable);
    $em->flush();

    return $custParams;
}

}

Problem polega na tym, że mogę ustawić to poprawnie przy pierwszym uruchomieniu klienta, ale za drugim razem sql wygenerowany przez doktrynę kończy się przy użyciu pierwszej utworzonej przeze mnie tabeli.

Jeśli więc uruchomię najpierw: CustomerX :: getCustomerRecords ('123'), sql, który zostanie uruchomiony i kiedy uruchomię CustomerX :: getCustomerRecords ('987') nadal używa 'customer_123'.

Muszę coś zrobić źle. Jeśli ktoś ma jakieś sugestie, jak poprawnie usunąć lub zresetować nazwę tabeli do czegoś nowego, byłoby świetnie.

Dzięki.

Początkowo użyłem tego jako odniesienia.Programowo zmodyfikuj nazwę schematu tabeli w Doctrine2?

questionAnswers(1)

yourAnswerToTheQuestion