Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
978 views
in Technique[技术] by (71.8m points)

symfony - Symfony2 and Doctrine - Error: Invalid PathExpression. Must be a 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. 

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');

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

SELECT IDENTITY(c.parent) ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...