无效的PathExpression

无效的PathExpression

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

问题描述

我正在使用createQueryBuilder创建这样的查询

I'm using createQueryBuilder to create a query like this

$result = $qb->select('csr.id,csr.survey')
              ->from('Entity\ClientSurveyRecord', 'csr')
              ->innerJoin('Entity\AbstractClientRecord','cr','WITH','cr.id = csr.id')
              ->innerJoin('Entity\Client','c','WITH','cr.client = c.id')
              ->where('csr.survey = :id_survey')
              ->setParameter('id_survey',$id)
              ->getQuery()
              ->getResult();

我得到以下消息类型:Doctrine\ORM\Query\QueryException

And I get the following message Type: Doctrine\ORM\Query\QueryException

Message: [Semantical Error] line 0, col 18 near 'survey FROM Entity\ClientSurveyRecord': Error: Invalid PathExpression. Must be a StateFieldPathExpression.

Filename: /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php

但是如果我将<$ c $更改为 $ qb-> select('csr.id,csr.survey') c> $ qb-> select('csr.id')有效

But if I change $qb->select('csr.id,csr.survey') for $qb->select('csr.id') it works

这是映射文件

Entity\ClientSurveyRecord:
    type: entity
    table: clients_survey_records

    fields:

        result:
            type: integer
            column: result
            nullable: false
            options:
                comment: Client survey current result.

    manyToOne:
        survey:
            targetEntity: Entity\AbstractSurvey
            joinColumn:
                name: id_survey
                referenceColumnName: id
                nullable: false

        surveyShipmentTracking:
            targetEntity: Entity\SurveyShipmentTracking
            joinColumn:
                name: id_survey_shipment_tracking
                referenceColumnName: id
                nullable: false


推荐答案

您需要使用其映射的属性来加入关系对于调查,您需要将其加入到查询生成器对象中

You need to join your relations using their mapped properties like for survey you need to join this in your query builder object

$result = $qb->select(['csr.id','s']) // or add column names ['csr.id','s.id','s.title', ...]
              ->from('Entity\ClientSurveyRecord', 'csr')
              ->innerJoin('csr.survey','s')
              ->innerJoin('Entity\AbstractClientRecord','cr','WITH','cr.id = csr.id')
              ->innerJoin('Entity\Client','c','WITH','cr.client = c.id')
              ->where('s.id = :id_survey')
              ->setParameter('id_survey',$id)
              ->getQuery()
              ->getResult();

另外,如果您加入 Entity\AbstractClientRecord Entity\Client 使用一些已映射的属性,例如您已经完成了调查,例如

Also it would be good if you join Entity\AbstractClientRecord and Entity\Client using some mapped properties like you have already done for survey , like

$result = $qb->select(['csr.id','s'])
              ->from('Entity\ClientSurveyRecord', 'csr')
              ->innerJoin('csr.survey','s')
              ->innerJoin('csr.abstractClientRecord','cr')
              ->innerJoin('cr.client','c')
              ->where('s.id = :id_survey')
              ->setParameter('id_survey',$id)
              ->getQuery()
              ->getResult();

这篇关于错误:无效的PathExpression。必须是StateFieldPathExpression,但无法选择字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:13