2016-09-20 2 views
0

Можно ли переопределить @ManyToOne(targetEntity)?Doctrine 2, отменяющий много к одной ассоциации

Я прочитал this Doctrine documentation page, но не упоминает, как переопределить targetEntity.

Вот мой код:

namespace AppBundle\Model\Order\Entity; 

use AppBundle\Model\Base\Entity\Identifier; 
use AppBundle\Model\Base\Entity\Product; 
use Doctrine\ORM\Mapping as ORM; 
use Doctrine\ORM\Mapping\AttributeOverrides; 
use Doctrine\ORM\Mapping\AttributeOverride; 

/** 
* Class OrderItem 
* 
* 
* @ORM\Entity 
* @ORM\Table(name="sylius_order_item") 
* @ORM\AssociationOverrides({ 
*  @ORM\AssociationOverride(
*   name="variant", 
*   [email protected]\JoinColumn(
*    name="variant", referencedColumnName="id", nullable=true 
*   ) 
*  ) 
* }) 
*/ 
class OrderItem extends \Sylius\Component\Core\Model\OrderItem 
{ 

    /** 
    * @var 
    * @ORM\ManyToOne(targetEntity="AppBundle\Model\Base\Entity\Product") 
    */ 
    protected $product; 

    /** 
    * @return mixed 
    */ 
    public function getProduct() 
    { 
     return $this->product; 
    } 

    /** 
    * @param mixed $product 
    */ 
    public function setProduct($product) 
    { 
     $this->product = $product; 
    } 
} 

Я был в состоянии отменить определение для столбца «вариант» и установите этот столбец пустое значение, но я не могу понять, как изменить targetEntity.

ответ

0

Как описано в док, вы не можете изменить тип вашей ассоциации: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#association-override

НО, вы можете определить targetEntity как интерфейс (это sylius по умолчанию конф тем он кажется),

targetEntity="AppBundle\Entity\ProductInterface" 

Расширяет оригинал в файле интерфейса

namespace AppBundle\Entity;  
use Sylius\Component\Core\Model\ProductInterface as BaseProductInterface; 
interface ProductInterface extends BaseProductInterface {} 

И добавить отображение в конфигурации

doctrine: 
    orm: 
     resolve_target_entities: 
      AppBundle\Entity\ProductInterface: AppBundle\Entity\Product 

Это описано здесь: http://symfony.com/doc/current/doctrine/resolve_target_entity.html

Надеется, что это помогает