【问题标题】:PHP / Symfony issue "Unknown record property"PHP / Symfony 问题“未知记录属性”
【发布时间】:2021-07-13 08:36:55
【问题描述】:

下面的PHP执行代码抛出错误

$q = Doctrine::getTable('FormSurvey')->querySurveyByFormRequest($form_request);
$this->results = $q->execute();

public function querySurveyByFormRequest($form_request) {
      $q = Doctrine_Query::create();
      $q->from('FormSurvey FS');
      $q->leftJoin('FS.FormQuestion FQ');
      $q->leftJoin('FQ.Question Q');
      $q->leftJoin('Q.QuestionText QT');
      $q->leftJoin('Q.QuestionSingle QS');
      $q->leftJoin('Q.QuestionMultiple QM');
      $q->leftJoin('QT.Answers AT with AT.form_request_id = ?', $form_request->getId());
      $q->leftJoin('QS.AnswerSingle AS with AS.form_request_id = ?', $form_request->getId());
      $q->leftJoin('QM.AnswerMultiple AM with AM.form_request_id = ?', $form_request->getId());
      $q->where('FS.id = ?', $form_request->getFormSurveyId());
      $q->orderBy('FQ.displayOrder');
      return $q;
    }

$q->getSqlQuery() Query String 在 SQLYog 中工作正常,但是当我们使用 PHP execute() 时,它会抛出未知记录属性错误@

错误信息

Unknown record property / related component "<pre>\nalias : FormSurvey\nforeign : id\nlocal : form_survey_id\nclass : FormSurvey\ntype : 0\ntable : Object(FormSurveyTable)\nlocalTable : Object(FormQuestionTable)\nname : \nrefTable : \nonDelete : \nonUpdate : \ndeferred : \ndeferrable : \nconstraint : \nequal : \ncascade : Array\nowningSide : \nrefClassRelationAlias : \nforeignKeyName : \norderBy : \n</pre>" on "FormQuestion", referer: system/applications/referenceforms.html

【问题讨论】:

  • 哇。有一段时间没有看到使用 Doctrine 1。我真正能建议的就是注释掉所有左连接,然后一次将它们添加回来以尝试缩小问题范围。

标签: php doctrine-orm dql


【解决方案1】:

通过添加 $q->select('FS.*'); 解决了上述问题在查询之前,所以新查询是

      $q = Doctrine_Query::create();
      $q->select('FS.*');
      $q->from('FormSurvey FS');
      $q->leftJoin('FS.FormQuestion FQ');
      $q->leftJoin('FQ.Question Q');
      $q->leftJoin('Q.QuestionText QT');
      $q->leftJoin('Q.QuestionSingle QS');
      $q->leftJoin('Q.QuestionMultiple QM');
      $q->leftJoin('QT.Answers AT with AT.form_request_id = ?', $form_request->getId());
      $q->leftJoin('QS.AnswerSingle AS with AS.form_request_id = ?', $form_request->getId());
      $q->leftJoin('QM.AnswerMultiple AM with AM.form_request_id = ?', $form_request->getId());
      $q->where('FS.id = ?', $form_request->getFormSurveyId());
      $q->orderBy('FQ.displayOrder');
      return $q;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    相关资源
    最近更新 更多