2017-08-17 49 views
1

我在\vendor文件夹中有一个实体,我无法更改/触摸,但是当我在项目中使用它时,我需要为该对象添加一个参数(description)。从供应商文件夹中扩展实体

所以我有代码:

namespace SoftNation\Sylius\MyExtendBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use SoftNation\Sylius\ExtendBundle\Entity\ExtendTranslation; 

/** 
* @ORM\Table(name="softnation_sylius_extend_translation") 
*/ 
class MyExtendTranslation extends ExtendTranslation 
{ 
    /** 
    * @ORM\Column(type="text") 
    */ 
    protected $description; 

    /** 
    * @return string 
    */ 
    public function getDescription() 
    { 
      return $this->description; 
    } 

    /** 
     * @param string $description 
     */ 
    public function setDescription($description) 
    { 
     $this->description = $description; 
    } 
} 

现在当我尝试:

bin/console doctrine:migrations:diff 

我得到一个错误:

[Doctrine\DBAL\Schema\SchemaException]          
The table with name 
'shop_beta_dev.softnation_sylius_extend_translation' already exists. 

所有我想要的是,我可以这样做:

$extend = new ExtendTranslation; 
$extend->setDescription('StackOverflowRocks'); 
+0

取读通过FOSUserBundle。它展示了如何扩展一个用户实体。我忘记了所有涉及的内容,但文档将引导您阅读它。 – Cerad

+1

ExtendTranslation类是否具有定义表的Doctrine Entity注释?当有两个具有相同表名声明的实体时,会出现该错误。 – tlorens

+1

也许[文档](http://docs.sylius.org/en/latest/customization/index.html)可以提供帮助吗?有一部分用于扩展模型。 – ccKep

回答