Symfony2和Doctrine - 错误:PathExpression无效。必须是StateFieldPathExpression [英] Symfony2 and Doctrine - Error: Invalid PathExpression. Must be a StateFieldPathExpression

查看:206
本文介绍了Symfony2和Doctrine - 错误:PathExpression无效。必须是StateFieldPathExpression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的实体:

/**
 * @Gedmo\Tree(type="nested")
 * @ORM\Table(name="categories")
 * @ORM\Entity()
 */
class Category extends BaseCategory
{

    /**
    * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
    */
    protected $children;

    /**
    * @Gedmo\TreeParent
    * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
    * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
    */
    protected $parent;

}

我正在尝试运行这样的查询: / p>

and I am trying to run a query like this:

$qb = $this->em->createQueryBuilder()
            ->select('c.parent')
            ->from('Category', 'c');

$result = $qb->getQuery()->getArrayResult();

但是,我收到以下错误:

However, I am getting the following error:

[Semantical Error] ... Error: Invalid PathExpression. Must be a StateFieldPathExpression. 

如何从我的表中选择parent_id字段。我已经尝试过一些变体,即使我做了这样的事情:

How can I select the parent_id field from my table. I have tried a bunch of variations and even if I do something like this:

$qb = $this->em->createQueryBuilder()
            ->select('c')
            ->from('Category', 'c');

我将parent_id中的表之外的所有字段。这似乎是教条正在阻碍。如何查询此parent_id字段?或更好,但如何获得表中的所有字段,包括 parent_id

I get all fields in the table except for the parent_id. This seems like Doctrine is getting in the way. How can I query for this parent_id field? or better yet how can I get all fields in the table including the parent_id

推荐答案

您可以使用当前未记录的 IDENTITY 函数在查询中选择FK ID:

You can use the currently undocumented IDENTITY function to select the FK IDs in a query:

SELECT IDENTITY(c.parent) ...

这篇关于Symfony2和Doctrine - 错误:PathExpression无效。必须是StateFieldPathExpression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆