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

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

问题描述

我有一个看起来像这样的实体:

I have an entity that looks like this:

/**
 * @GedmoTree(type="nested")
 * @ORMTable(name="categories")
 * @ORMEntity()
 */
class Category extends BaseCategory
{

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

    /**
    * @GedmoTreeParent
    * @ORMManyToOne(targetEntity="Category", inversedBy="children")
    * @ORMJoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
    */
    protected $parent;

}

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

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 之外的所有字段.这似乎是 Doctrine 的阻碍.如何查询这个 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天全站免登陆