Search code examples
phpdoctrine-ormdql

PHP / Symfony issue "Unknown record property"


Below PHP execute code is throwing an error

$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 working fine in SQLYog but it is throwing below Unknown record property error when we use PHP execute()

Error message

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

Solution

  • Resolved the above issue by adding $q->select('FS.*'); before query, so new query is

          $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;