mysqlmappingdoctrine-orm

Doctrine2 workaround for mapping MySql 'bit' data type


I have a few columns in my database schema that have bit data types and am having problems with Doctrine2 mapping it. I keep getting:

Unknown database type bit requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

Is there any work around? I was thinking of just changing the data type to boolean and just use true and false statements but that would mean changing the schema on a large scale which I dont have time for.


Solution

  • You could create your own, custom type for Doctrine.

    1. Create a new type by extending Doctrine\DBAL\Types\Type class.
    2. Override convertToPHPValue() and convertToDatabaseValue() methods.
    3. Register a new type:

      \Doctrine\DBAL\Types\Type::addType('abc', 'Your\\Custom\\Type\\AbcType');
      
      $dbPlatform = $em->getConnection()->getDatabasePlatform();
      $dbPlatform->registerDoctrineTypeMapping('abc', 'abc');
      

    Read more on Doctrine's documentation pages