2013-03-27 1 views
10

을 변경 다음을 포함합니다 :교리의 사용자 정의 유형은 항상 내가 같은 사용자 정의 유형을 추가 한 테이블

php app/console doctrine:schema:update --dump-sql 

나는 다음과 점점 계속 :

ALTER TABLE product_price CHANGE price price DECIMAL(10,2) DEFAULT NULL 

그 외에도 모두에서 매우 잘 작동합니다. DB의 필드가 정확합니다. doctrine이 동일한 데이터로 계속 업데이트되는 이유가 있습니까?

+0

버그가있는 것 같습니다. http://www.doctrine-project.org/jira/browse/DBAL-353?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel – mentalic

+1

문제가 해결되었습니다. 그것이 재현 불가능하기 때문에 불완전한 것으로 – Ocramius

답변

3

DBAL 플랫폼에 유형에 대해 알려주지 않으므로 분명히 DBAL 스키마 내성 유틸리티가이를 인식하지 못합니다. 유형을 등록하려면 다음을 수행 할 수

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); 
     } 
    } 
} 

이 스키마의 차이에 대해 불평에서 DBAL을 중지해야합니다.

+0

-> registerDoctrineTypeMapping ('decimal', Money :: MONEY); OR -> registerDoctrineTypeMapping ('decimal (10,2)', Money :: MONEY); ? – mentalic

+1

특정 매개 변수가 있어야합니다. – Ocramius

+0

도움 주셔서 감사합니다. 불행히도 그것은 속임수를 쓰지 않았습니다. 3 가지 유형 (Money, Weight 및 Quantity)이 모두 10 진수 (10,2)의 결과가 될 수 있습니까? 부트 섹션에서 나는 제안한 모든 것을 십진수로 선언했다. – mentalic

4

구성을 사용하여이를 수행 할 수있는 다른 방법이 있습니다.

config.yml :

doctrine: 
    dbal: 
     types: { money: My\SuperBundle\Types\Money } 

    connections: 
     your_connection_name: 
      mapping_types: { money: money } 

출처 :

+2

감사합니다. "connections"섹션을 사용하지 않으면 "mapping_types"항목을 "dbal"섹션에 직접 입력 할 수 있습니다. – tiho

8

당신은 방법 requiresSQLCommentHint(AbstractPlatform $platform)을 무시하고 true를 반환해야합니다. 그렇게해서, 교리는 습관 유형을 기억할 것입니다.

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; 
    } 
} 

출처 :

1

Use column comments for further Doctrine Type Inference 내가 ZF2과 같은 문제가 있었다.

해결 방법 내 맞춤 유형 이름에 하이픈을 제거하여 을 해결했습니다.

잘못된 :

'doctrine_type_mappings' => [ 
    'custom-type' => 'custom-type' 
], 

좋은 : 젠드 프레임 워크 2의 구현에 대한

'doctrine_type_mappings' => [ 
    'customtype' => 'customtype' 
], 

자세한 내용 :이 사람을 도울 수 있기를 바랍니다 https://github.com/doctrine/DoctrineORMModule/blob/master/docs/EXTRAS_ORM.md

.

관련 문제