【问题标题】:Symfony ORM Annotation in Trait doesn't work as expectedTrait 中的 Symfony ORM 注释无法按预期工作
【发布时间】:2014-03-11 23:09:31
【问题描述】:

当我在类中使用 Trait 时,会添加字段和方法,但会丢失部分 ORM 注释。
示例:
文件:CommonFields.php

Trait Commonfields
{
    /**
     * @ORM\Column(name="test", type="string", length=255, nullable=true)
     */
    private test;

    public function getTest()
    {
         return $this->test;
    }

    public function setTest($test)
    {
        $this->test = $test;
    }
}

文件:My.php

class My
{
    use CommonFields;
    // ...the rest of My class 

}

当我将实体与数据库同步时:php app/console dictionary:schema:update --force 我丢失了@ORM 注释中指定的“可为空”和“长度”选项。 如果我在 Class My 中定义相同的字段和相关注解,它会按预期工作。

【问题讨论】:

    标签: php symfony orm doctrine-orm traits


    【解决方案1】:

    我知道这很旧,但我遇到了同样的问题,我通过清除缓存然后php app/console doctrine:schema:update --force修复它

    希望有人觉得这很有用。

    【讨论】:

      【解决方案2】:

      在处理实体时,您可能应该使用映射的超类。

      http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html

      【讨论】:

      猜你喜欢
      • 2018-08-06
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多