为什么doctrine可以通过虚拟连接列进行排序并具有setMaxResult和setFirstResult?

时间:2016-10-10 13:16:07

标签: php sql-server symfony doctrine-orm

我有以下问题: 我想从实体中选择一些字段,并为每个选定的行计算一些来自另一个表的行。

我运行以下代码:

    $qb = $this->createQueryBuilder('ff')
               ->select('ff as feedbackForm, COUNT(ffa.id) as completedForms')
               ->leftJoin('AppBundle:FeedbackFormAction', 'ffa', 'WITH','ffa.feedbackForm = ff.id ')
               ->groupBy('ff');

    if (!empty($pageSize)) {
        $qb->setMaxResults($pageSize);
    }

    if (!empty($offset)) {
        $qb->setFirstResult($offset);
    }

    if (!empty($orderBy)) {
        if ($orderBy != 'completedForms') {
            $orderBy   = "ff." . $orderBy;
        }
        $qb->orderBy($orderBy, $direction);
    }
    return $qb->getQuery()->getArrayResult();
}

主要的问题是,当我想通过completedForms订购并且$ pageSize和$ offset是SET时,doctrine无法处理代码,它说:

  

消息:执行' SELECT * FROM时发生异常(SELECT ROW_NUMBER()OVER(ORDER BY sclr_12 DESC)AS doctrine_rownum,m0_.id AS id_0,m0_.start_date AS start_date_1,m0_.end_date AS end_date_2, m0_.active AS active_3,m0_.completed_required AS completed_required_4,m0_.section AS section_5,m0_.form_question AS form_question_6,m0_.count_completed AS count_completed_7,m0_.count_canceled AS count_canceled_8,m0_.created_at AS created_at_9,m0_.updated_at AS updated_at_10,m0_。 deleted_at AS deleted_at_11,COUNT(m1_.id)AS sclr_12 FROM feedback_forms m0_ LEFT JOIN feedback_form_actions m1_ ON(m1_.feedback_form = m0_.id)WHERE m0_.deleted_at IS NULL GROUP BY m1_.id,m1_.created_at,m1_.feedback_form,m1_ .user_id)AS doctrine_tbl WHERE doctrine_rownum BETWEEN 2和6' with params [2]:SQLSTATE [HY000]:常规错误:207常规SQL Server错误:检查来自SQL Server的消息[207](严重级16)[(null)] [] []

但是当我只设置$ pageSize OR $ offset和ORDER BY completedForms列时,我得到了预期的结果。问题是当我设置两个变量($ pageSize和$ offset)时。

0 个答案:

没有答案