DC2Type:array 在进行 Doctrine 迁移差异时将评论添加到字段
DC2Type:array comment being added to field when doing a Doctrine migration diff
当我 运行 doctrine:migrations:diff
我有一个未执行的迁移与 table 和我没有更改的实体有关。
这是生成的 SQL:
ALTER TABLE crmpicco_course_guide_row CHANGE courses courses
LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\'
这是映射实体和第一次创建table时生成的原始SQL:
courses LONGTEXT DEFAULT NULL
我的学说映射:
courses:
type: array
nullable: true
我的实体:
/**
* @var array
*/
protected $courses = array();
/**
* {@inheritdoc}
*/
public function getCourses()
{
return $this->courses;
}
/**
* @param array $courses
*/
public function setCourses(array $courses)
{
$this->courses = $courses;
}
为什么要添加评论,有没有办法防止它在 diff
期间出现?
评论已添加because of this method:
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
您可以覆盖现有的 class 并使用您的自定义 class return false:
<?php
namespace My\DBAL\Types;
/**
* Overwrite array type to prevent comment hint
*/
class ArrayType extends \Doctrine\DBAL\Types\ArrayType
{
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return false;
}
}
并按如下方式注册您的自定义类型:
'doctrine' => array(
// ...other config
'configuration' => array(
'orm_default' => array(
'types' => array(
'array' => 'My\DBAL\Types\ArrayType'
)
)
)
)
当我 运行 doctrine:migrations:diff
我有一个未执行的迁移与 table 和我没有更改的实体有关。
这是生成的 SQL:
ALTER TABLE crmpicco_course_guide_row CHANGE courses courses
LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\'
这是映射实体和第一次创建table时生成的原始SQL:
courses LONGTEXT DEFAULT NULL
我的学说映射:
courses:
type: array
nullable: true
我的实体:
/**
* @var array
*/
protected $courses = array();
/**
* {@inheritdoc}
*/
public function getCourses()
{
return $this->courses;
}
/**
* @param array $courses
*/
public function setCourses(array $courses)
{
$this->courses = $courses;
}
为什么要添加评论,有没有办法防止它在 diff
期间出现?
评论已添加because of this method:
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
您可以覆盖现有的 class 并使用您的自定义 class return false:
<?php
namespace My\DBAL\Types;
/**
* Overwrite array type to prevent comment hint
*/
class ArrayType extends \Doctrine\DBAL\Types\ArrayType
{
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return false;
}
}
并按如下方式注册您的自定义类型:
'doctrine' => array(
// ...other config
'configuration' => array(
'orm_default' => array(
'types' => array(
'array' => 'My\DBAL\Types\ArrayType'
)
)
)
)