Doctrine custom type always altering table

后端 未结 4 1829
醉话见心
醉话见心 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:19

    You have to override the method requiresSQLCommentHint(AbstractPlatform $platform) and return true. Like that, doctrine will remember the custom type.

    namespace My\SuperBundle\Types;
    
    use Doctrine\DBAL\Types\Type;
    use Doctrine\DBAL\Platforms\AbstractPlatform;
    
    class Money extends Type
    {
        const MONEY = 'money';
    
        public function getSqlDeclaration(
            array $fieldDeclaration,
            AbstractPlatform $platform
        ) {
            return 'DECIMAL(10,2)';
        }
    
        public function getName()
        {
            return self::MONEY;
        }
    
        /**
         * @inheritdoc
         */
        public function requiresSQLCommentHint(AbstractPlatform $platform)
        {
            return true;
        }
    }
    

    Source: Use column comments for further Doctrine Type Inference

提交回复
热议问题