错误:无效的PathExpression。通过Doctrine选择查询后必须是StateFieldPathExpression

时间:2018-03-19 17:33:52

标签: mysql database symfony orm doctrine

    return $this->entityManager
        ->createQueryBuilder()
        ->select('cac.fkClient', 'cac.fkIndividualConsultation', 'cac.dateAdded', 'cac.fkWorker')
        ->from(ClientActivityIndividualConsultationHistory::class, 'cac')
        ->where('cac.dateAdded BETWEEN :startDate AND :endDate')
        ->andWhere('cac . fkWorker = :workerId')
        ->setParameters([
            'startDate' => $dateStart,
            'dateEnd' => $dateEnd,
            'workerId' => $workerId
        ])
        ->getQuery()
        ->getArrayResult();

错误讯息:

  

[语义错误]第0行,第11行靠近fkClient,   cac.fkIndividualConsultation,':错误:无效的PathExpression。一定是   一个StateFieldPathExpression。

ORM:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Sepc\Bundle\WebBundle\Entity\ClientActivityIndividualConsultationHistory"
            table="client_activity_individual_consultation_history">
        <indexes>
            <index name="fk_client_activity_individual_consulation_history_worker_id" columns="fk_worker_id"/>
            <index name="fk_client_activity_individual_consulation_history_client_id" columns="fk_client_id"/>
            <index name="fk_client_individual_consulation_history_consultation_id"
                   columns="fk_individual_consultation_id"/>
        </indexes>
        <id name="id" type="integer" column="id">
            <generator strategy="IDENTITY"/>
        </id>
        <field name="dateAdded" type="datetime" column="date_added" nullable="false">
            <options>
                <option name="default">CURRENT_TIMESTAMP</option>
            </options>
        </field>
        <many-to-one field="fkClient" target-entity="Client" fetch="LAZY">
            <join-columns>
                <join-column name="fk_client_id" referenced-column-name="id"/>
            </join-columns>
        </many-to-one>
        <many-to-one field="fkWorker" target-entity="Worker" fetch="LAZY">
            <join-columns>
                <join-column name="fk_worker_id" referenced-column-name="id"/>
            </join-columns>
        </many-to-one>
        <many-to-one field="fkIndividualConsultation" target-entity="CalendarIndividualConsultation" fetch="LAZY">
            <join-columns>
                <join-column name="fk_individual_consultation_id" referenced-column-name="id"/>
            </join-columns>
        </many-to-one>
    </entity>
</doctrine-mapping>

我尝试了所有东西(stackoverflow,谷歌,自己的expierences),但我真的不知道哪里可能有问题。有人可以解释我这个错误或导航我的正确方法吗?谢谢。

我不想使用IDENTITY函数,因为我需要所有与外键相关的数据。 (Doctrine自动选择这些对象,我认为这会产生错误,但为什么呢?)

使用:Symfony FW,Doctrine 2 ORM,MySQL

我的提示:

  1. 错误的ORM生成文件
  2. QueryBuilder错误

3 个答案:

答案 0 :(得分:0)

你应该加入 fkClient,fkIndividualConsultation和fkWorker关系,以便选择它们。

所以改为:

<div class="modal" id="Gallerie">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
                <div class="carousel-inner">
                    <div class="carousel-item active">
                        <img class="d-block w-100" src="http://placehold.it/400x300" alt="First slide">
                    </div>
                    <div class="carousel-item">
                        <img class="d-block w-100" src="http://placehold.it/400x300" alt="Second slide">
                    </div>
                    <div class="carousel-item">
                        <img class="d-block w-100" src="http://placehold.it/400x300" alt="Third slide">
                    </div>
                </div>
                <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
                    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                    <span class="sr-only">Previous</span>
                </a>
                <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
                    <span class="carousel-control-next-icon" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                </a>
            </div>
        </div>
    </div>
</div>

答案 1 :(得分:0)

   return $this->entityManager
                ->createQueryBuilder()
                ->select('cac')
                ->distinct('cac.fkClient')
                ->from(ClientActivityIndividualConsultationHistory::class, 'cac')
                ->where('cac.dateAdded BETWEEN :startDate AND :endDate')
                ->andWhere('cac . fkWorker = :workerId')
                ->setParameters([
                    'startDate' => $dateStart,
                    'endDate' => $dateEnd,
                    'workerId' => $workerId
                ])
                ->getQuery()
                ->getResult();

固定。

使用 getResult()函数代替getArrayResult();

谢谢大家。

答案 2 :(得分:0)

您可以按以下方式选择语句:

SELECT IDENTITY(c.parent) ...

它将返回ID,然后您可以按照以下方法在getResult()方法中将其与对象混合:

->getResult(AbstractQuery::HYDRATE_OBJECT);