Symfony2 Doctrine:在另一个包的继承 class 中重新定义注解

Symfony2 Doctrine: redefine annotation in a inheritance class from another bundle

我有一个 CompanyBundle 捆绑包: class 里面有这个的产品

/**
 * @ORM\ManyToMany(targetEntity="CompanyBundle\Entity\ProductImage", inversedBy="listProduct")
 **/
private $listProductImage;

和一个 class ProductImage 有这个:

/**
 * @ORM\ManyToMany(targetEntity="CompanyBundle\Entity\Product", mappedBy="listProductImage")
 */
private $listProduct;

但我也像这样从另一个 ClinetBundle 扩展了我的 class 产品:

/**
 * @ORM\Entity(repositoryClass="ClientBundle\Entity\Repository\ClientProductRepository")
 */
class ClientProduct extends Product
{
    /**
     * @ORM\ManyToMany(targetEntity="ClientBundle\Entity\ClientProductImage", inversedBy="listProduct")
     **/
    private $listProductImage;
}

但是当我在我的控制器中构建一个 ClientProduct 对象 class 并且我尝试从它访问 ClientProductImage 时,它​​给出了来自 CompanyBundle 的 class,而不是 ClientBundle。那么,我该怎么做才能从 ClientBundle 获取 ProductImage?

就像我的 /** @ORM\ManyToMany(targetEntity="ClientBundle\Entity\ClientProductImage", inversedBy="listProduct") **/ 什么也没做:(

感谢您的帮助!

我终于找到了解决办法。

我不保留 ClientProduct 中定义的无用关系。 所以我删除了 ManyToMany(targetEntity="ClientBundle\Entity\ClientProductImage"

然后,我打开 app/config.yml 并添加 resolve_target_entities:

doctrine:
    ...
    orm:
        ...
        resolve_target_entities:
           CompanyBundle\Entity\ProductImage: ClientBundle\Entity\ClientProductImage

一切正常,我不需要更改 CompanyBundle :)