尝试加入不同捆绑包中的2个不同实体失败


Trying to join 2 different entities in different bundles, failed

我正试图在Symfony2中启动一个查询(我是新手),在那里我需要加入不同捆绑包中的两个不同实体:

  • Candc/ComercioBundle/实体/Venta/ItemVentaCarta和
  • Candc/ProductoBundle/实体/Producto

他们有一对一的关系。

Class Producto/////
    /**
     *
     * @ORM'Id
     * @ORM'Column(name="id", type="integer")
     * @ORM'OneToMany(targetEntity="Candc'ComercioBundle'Venta'ItemVentaCarta", mappedBy="Producto")
     * @ORM'GeneratedValue(strategy="AUTO")
     */
    private $id;

和:

Class ItemVentaCarta//////
    /**
     * catalog card wich is referenced.
     * @ORM'ManyToOne(targetEntity="'Candc'ProductoBundle'Entity'Producto", inversedBy="ItemVentaCarta")
     * @ORM'JoinColumn(name="carta_id", referencedColumnName="id", nullable=false)
     */ 
    private $carta;

这是我正在启动的查询:

public function findLastProducts(){
//this is what I need to do in SQL language :
            $consulta = 'SELECT * FROM c_venta_item 
                LEFT JOIN c_venta_item_carta 
                ON c_venta_item.id=c_venta_item_carta.id
                LEFT JOIN usuario ON c_venta_item.user_id = usuario.id
                LEFT JOIN producto ON c_venta_item_carta.carta_id = producto.id';
            return $this->getEntityManager()
                ->createQuery("SELECT ivc
                    FROM 'Candc'ComercioBundle'Entity'Venta'ItemVentaCarta ivc
                    LEFT JOIN ivc.producto p
                    WHERE ivc.carta = p.id")
                ->getResult();
    }

我在Symfony 2.7.7,我得到的例外是:

[语义错误]第0行,第105列,靠近'pWHERE’:错误:Class Candc''CommercioBundle''Entity''Venta''ItemVentaCarta没有名为producto 的关联

(为了避免打字错误,我同时尝试了producto和producto)也在论坛上搜索,发现了很多相关的帖子,但无法解决。

我清除了缓存,还尝试了模式更新,但我收到了一条消息,上面写着:

"没有什么可以更新的,伙计,你的数据库已经与实体元数据同步了;

Hi-DQL绑定到对象属性,而不是映射的实体名称,请通过以下操作更新您的代码:

Class ItemVentaCarta//////
    /**
     * catalog card wich is referenced.
     * @ORM'ManyToOne(targetEntity="'Candc'ProductoBundle'Entity'Producto", inversedBy="ItemVentaCarta")
     * @ORM'JoinColumn(name="carta_id", referencedColumnName="id", nullable=false)
     */ 
    private $producto; // previously $carta

此外,看起来您的查询需要更改为:

SELECT ivc 
FROM 'Candc'ComercioBundle'Entity'Venta'ItemVentaCarta ivc
LEFT JOIN ivc.producto p ON ivc.carta = p.id