Doctrine custom data type
Asked Answered
T

2

10

I'm developing application with Symfony2. Symfony2 is using Doctrine 2 for DBAL and ORM. As far as I know Doctrine2 doesn't have suport for BLOB data type. However I want to implement BLOB support through the custom data type mapping:

http://www.doctrine-project.org/docs/dbal/2.0/en/reference/types.html

However I'm struggling to understand where should this part go.

<?php
Type::addType('money', 'My\Project\Types\MoneyType');
$conn->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney', 'money');

Is anybody was going through it?

The reason I need a BLOB type is that I want to import mapping from existing MySQL database.

Tufa answered 29/1, 2011 at 15:11 Comment(1)
just answered this here: https://mcmap.net/q/1164796/-how-add-blob-type-in-doctrine-2-using-symfony-2Urology
K
9

Another solution would be to register your Custom Type in the config file

You just need to add that in your config file:

# app/config/config.yml
doctrine:
    dbal:
        types:
            money:  My\Project\Types\MoneyType

You can find more info on how to register a custom mapping type in this Symfony Cookbook entry

Karissakarita answered 7/1, 2016 at 23:46 Comment(0)
P
4

According to the link in previous answer you can just add it to src/My/Project/MyProjectBundle.php

use My\Project\Types\MoneyType;

class MyProject extends Bundle
{
    public function boot()
    {
        $em = $this->container->get('doctrine.orm.entity_manager');
        Type::addType('money', MoneyType::class);
        $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney','money');
    }
}
Pipette answered 6/2, 2013 at 1:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.