Error: Invalid PathExpression. Must be a StateFiel

2019-07-25 10:12发布

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

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

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

this is the mapping file

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

1条回答
相关推荐>>
2楼-- · 2019-07-25 10:54

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

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();
查看更多
登录 后发表回答