Doctrine custom type always altering table

后端 未结 4 1835
醉话见心
醉话见心 2021-02-08 08:46

I have added a custom type like:

namespace My\\SuperBundle\\Types;

use Doctrine\\DBAL\\Types\\Type;
use Doctrine\\DBAL\\Platforms\\AbstractPlatform;

class Mo         


        
4条回答
  •  别那么骄傲
    2021-02-08 09:01

    You are not telling the DBAL platform about your type, so obviously, the DBAL schema introspection utilities cannot recognize it. To register the type, you can do following:

    use Doctrine\DBAL\Types\Type;
    use My\SuperBundle\Types\Money;
    
    class MyBSuperBundle extends Bundle
    {
        public function boot()
        {
            /* @var $em \Doctrine\ORM\EntityManager */
            $entityManager = $this->container->get('doctrine.orm.entity_manager');
    
            if( ! Type::hasType(Money::MONEY)) {
                Type::addType(Money::MONEY, 'My\SuperBundle\Types\Money');
                $entityManager
                    ->getConnection()
                    ->getDatabasePlatform()
                    ->registerDoctrineTypeMapping('decimal', Money::MONEY);
            }
        }
    }
    

    This should stop the DBAL from complaining about schema differences.

提交回复
热议问题