调用未定义的方法Doctrine \ ORM \ QueryBuilder :: limit()

时间:2019-01-28 08:11:37

标签: mysql query-builder

调用未定义的方法Doctrine\ORM\QueryBuilder::limit()

我已经搜索了相关查询,但没有得到结果

public function getAllCTCCompensationData($ouCode,$langCode)
    { 
    $queryBuilder = $this->entityManager->createQueryBuilder();
    $queryBuilder->select('ppp.payperiodSdesc, ppesa.grossPay, pptpp.pfEmployerContribution, pptpp.esiEmployerContribution, pplw.employercontribution')
        ->from(PyProcessEmpStatusApproved::class, 'ppesa')
        ->leftJoin(PyProcessTdsPfPt::class, 'pptpp', 'with', 'ppesa.ouCode = pptpp.ouCode')
        ->leftJoin(PyPayGroup::class, 'ppg', 'with', 'pptpp.pgCode = ppg.pgCode')
        ->leftJoin(PyProcessLabourWelfare::class, 'pplw', 'with', 'ppg.pgCode = pplw.pgCode')
        ->leftJoin(PyPayPeriod::class,'ppp','with','pplw.payperiodCode = ppp.payperiodCode')
        ->leftJoin(PyPayrollCalendar::class, 'ppc', 'with', 'ppp.paycalCode = ppc.paycalCode')
                ->where('ppesa.ouCode = ?1')
                ->andWhere('ppesa.langCode = ?2')
                ->setParameter('1','ouCode')
                ->setParameter('2','langCode')
                ->where('ppesa.ouCode','DESC')
                ->limit(20);

    $compData  = $queryBuilder->getQuery()->getResult();

    return $compData;

我想在查询中应用限制条件。如何将限制应用于查询?

供参考,请使用此链接https://www.doctrine-project.org/projects/doctrine1/en/latest/manual/dql-doctrine-query-language.html#limit-and-offset-clauses

为什么说未定义的方法限制?

1 个答案:

答案 0 :(得分:0)

orderBy之前使用limit,我想这是错误的消息。

public function getAllCTCCompensationData($ouCode,$langCode)
{ 
    $queryBuilder = $this->entityManager->createQueryBuilder();
    $queryBuilder->select('ppp.payperiodSdesc, ppesa.grossPay, pptpp.pfEmployerContribution, pptpp.esiEmployerContribution, pplw.employercontribution')
        ->from(PyProcessEmpStatusApproved::class, 'ppesa')
        ->leftJoin(PyProcessTdsPfPt::class, 'pptpp', 'with', 'ppesa.ouCode = pptpp.ouCode')
        ->leftJoin(PyPayGroup::class, 'ppg', 'with', 'pptpp.pgCode = ppg.pgCode')
        ->leftJoin(PyProcessLabourWelfare::class, 'pplw', 'with', 'ppg.pgCode = pplw.pgCode')
        ->leftJoin(PyPayPeriod::class,'ppp','with','pplw.payperiodCode = ppp.payperiodCode')
        ->leftJoin(PyPayrollCalendar::class, 'ppc', 'with', 'ppp.paycalCode = ppc.paycalCode')
                ->where('ppesa.ouCode = ?1')
                ->andWhere('ppesa.langCode = ?2')
                ->setParameter('1','ouCode')
                ->setParameter('2','langCode')
                ->orderBy('ppesa.ouCode','DESC')
                ->limit(20);

    $compData  = $queryBuilder->getQuery()->getResult();

    return $compData;
}