猿问

在 WHERE 中使用 oneToMany 查询 DQL

此查询不起作用:


public function getByUnidadeAnoSemestre(int $unidadeId, int $ano, int $semestre) : array

{

    $query = $this->em->createQuery(

        'SELECT s,u,p FROM ' . 

            Servico::class . ' s ' .

        'INNER JOIN ' . 

            's.unidade u ' . 

        'INNER JOIN ' . 

            's.precificacoes p ' .

        'WHERE ' . 

            'u.id = :unidadeId ' . 

            'AND p.anoLetivo = :ano ' . 

            'AND p.semestre = :semestre'

    )->setParameters([

        "unidadeId" => $unidadeId,

        "anoLetivo" => $ano,

        "semestre" => $semestre

    ]);


    return $query->getResult();


}

Service 类中的映射是这样的:


/**

* @OneToMany(targetEntity="Precificacao", mappedBy="precificacoes", cascade={"persist"})

* @var Collection 

*/

private $precificacoes;


/**

* @ManyToOne(targetEntity="Unidade", inversedBy="id", cascade={"persist"})

* @JoinColumn(name="unidadeId", referencedColumnName="id")

* @var Unidade 

*/

private $unidade;

Slim 错误消息是:

“关联类型必须是 *_TO_ONE 或 MANY_TO_MANY 之一”

Php 控制台中的错误是:

PHP 注意:未定义的索引: precificacoes in D:\Projetos\FinanceiroEscolarApi\vendor\doctrine\orm\lib\Doctrine\ORM\Query\SqlWalker.php on line 946

你能帮助我吗?


绝地无双
浏览 199回答 1
1回答
随时随地看视频慕课网APP
我要回答