Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine2: Type x already exists

I have a problem with the Doctrine API.

I want to add a new Doctrine Type. I followed this documentation to create the class, and I have added the type in my custom driver.

Type::addType("custom", "Namespace\NameBundle\Types\CustomType");
$this->registerDoctrineTypeMapping("CustomType", "custom");

My problem append when I execute php app/console cache:clear.

[Doctrine\DBAL\DBALException]
Type custom already exists.

After few searches, I have found in Doctrine\DBAL\Types\Type::addType(…) throw an exception if the type is knew… I don't understand why this error is throwing.

like image 521
Baptiste Donaux Avatar asked Jan 02 '14 13:01

Baptiste Donaux


1 Answers

I have found my problem !

I don't know why, but my custom type is loading again and again.

To resolve this problem, adding this code like checking.

if (!Type::hasType("custom")) {
    Type::addType("custom", "Namespace\NameBundle\Types\CustomType");
    $this->registerDoctrineTypeMapping("CustomType", "custom");
}

It works !

like image 194
Baptiste Donaux Avatar answered Oct 17 '22 09:10

Baptiste Donaux