Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 634
Alex Foxx Farnsworth Avatar asked Mar 16 '12 21:03

Alex Foxx Farnsworth


2 Answers

Use mapping_types in the config.yml

doctrine:
    dbal:
        driver:%% database_driver
         host:%% database_host
         Port:%% database_port
         dbname:% database_name%
         user:%% database_user
         password:%% database_password
         charset: UTF8
         mapping_types:
             bit: boolean
like image 85
Seph Avatar answered Oct 02 '22 22:10

Seph


In case you are using BIT column to store a boolean, you do this:

// get currently used platform
$dbPlatform = $em->getConnection()->getDatabasePlatform();

// interpret BIT as boolean
$dbPlatform->registerDoctrineTypeMapping('bit', 'boolean');

Now every time you map a property to bit column, doctrine 2 will interpret its value as a boolean.

like image 36
Artur Bodera Avatar answered Oct 02 '22 22:10

Artur Bodera