【问题标题】:Access to inherit class attribute from DQL in Symfony2在 Symfony2 中访问从 DQL 继承类属性
【发布时间】:2013-04-05 10:31:09
【问题描述】:

我有一个抽象类 Product 和继承类 ProductWithRecurrency:

/**
 * @ORM\Table(name= "product")
 * @ORM\Entity(repositoryClass="Acme\StoreBundle\Entity\Repositories\ProductRepository")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="product_kind_id", type="integer")
 * @ORM\DiscriminatorMap({"1" = "ProductFoo", "2" = "ProductWithRecurring"})
 */
abstract class Product
{

}


/**
 *
 * @ORM\Table(name="product_with_recurring")
 * @ORM\Entity( repositoryClass ="Acme\StoreBundle\Entity\Repositories\ProductRepository")
 */
class ProductWithRecurring extends Product
{
    /**
     * @var Recurring $recurring
     *
     * @ORM\JoinColumn(name="recurring_id", referencedColumnName="id", nullable=false)
     */
    protected $recurring;
}

当产品是 ProductWithRecurring 的实例时,我需要获取一些混合产品并具有“重复”实体信息。我在 ProductRepository 中有一个带有这个 dql 的方法:

$dql = "SELECT p product
        FROM Acme\StoreBundle\Entity\Product p
        LEFT JOIN p.recurring rc
        WHERE p.some_conditions";

显然得到了这个异常:

[Semantical Error] line 0, col 1182 near 'rc
': Error: Class Acme\StoreBundle\Entity\Product has no association named recurring

我应该增加查询的复杂性还是我有概念错误?(我不是 Symfony 方面的专家,更不是 Doctrine)。

代码中可能有错误,我已将其简化以隔离问题。

我的英文不太好,希望你能理解我,谢谢!

【问题讨论】:

  • 当我在顶层添加重复属性时。不完全正确,但它有效。有什么帮助吗?谢谢!

标签: symfony doctrine dql


【解决方案1】:

您应该能够访问 ProductWithRecurring 中的所有产品属性。

使用下面的代码不起作用?我不太明白你想得到什么结果

$dql = "SELECT p
    FROM Acme\StoreBundle\Entity\ProductWithRecurring p
    WHERE p.some_conditions";

【讨论】:

    猜你喜欢
    • 2017-09-01
    • 1970-01-01
    • 2017-05-23
    • 2021-11-12
    • 2019-03-08
    • 2019-10-21
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多