Moodle
  1. Moodle
  2. MDL-30689

get_question_options Field Mismatch in question_answers

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.6
    • Fix Version/s: 2.0.7
    • Component/s: Questions
    • Labels:
    • Environment:
      windows IIS, MySQL
    • Database:
      MySQL
    • Testing Instructions:
      Hide

      This does not affect any core question types, just the ease with which people can write third-party ones. Hence it is a very safe changes, but very hard to test. I think we can safely add this with no testing.

      Show
      This does not affect any core question types, just the ease with which people can write third-party ones. Hence it is a very safe changes, but very hard to test. I think we can safely add this with no testing.
    • Workaround:
      Hide

      Override the function in your new question type or alter the main questiontype code.

      Further, for extending the questions table you use questionid_column_name in the same file. possibly create the same for answers or implement this function in the answer portion?

      Show
      Override the function in your new question type or alter the main questiontype code. Further, for extending the questions table you use questionid_column_name in the same file. possibly create the same for answers or implement this function in the answer portion?
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Pull from Repository:
    • Rank:
      33512

      Description

      If you look at the function get_question_options in 2.0.1+ (yes we plan on upgrading) in \moodle\question\type\questiontype.php you will see
      $extra_answer_fields = $this->extra_answer_fields();
      if (is_array($extra_answer_fields)) {
      $answer_extension_table = array_shift($extra_answer_fields);
      $question->options->answers = $DB->get_records_sql("
      SELECT qa.*, qax." . implode(', qax.', $extra_answer_fields) . "
      FROM

      {question_answers} qa, {$answer_extension_table} qax
      WHERE qa.questionid = ? AND qax.answerid = qa.id", array($question->id));
      if (!$question->options->answers) { echo $OUTPUT->notification("Failed to load question answers from the table $answer_extension_table for questionid " . $question->id); return false; }
      }

      note that
      SELECT qa.*, qax." . implode(', qax.', $extra_answer_fields) . "
      FROM {question_answers}

      qa, {$answer_extension_table} qax
      WHERE qa.questionid = ? AND qax.answerid = qa.id", array($question->id)

      uses 'qa.questionid' whereas in the database the field is called 'question'. Easy fix is override but...

        Activity

        Hide
        Tim Hunt added a comment -

        This is already fixed in 2.1+, but not in 2.0.6.

        I was not sure I could be bothered to fix it, but actually, it is so easy, I will.

        Show
        Tim Hunt added a comment - This is already fixed in 2.1+, but not in 2.0.6. I was not sure I could be bothered to fix it, but actually, it is so easy, I will.
        Hide
        Tim Hunt added a comment -

        To INTEGRATORS. This only needs to be fixed on the 2.0 branch.

        Show
        Tim Hunt added a comment - To INTEGRATORS. This only needs to be fixed on the 2.0 branch.
        Hide
        Sam Hemelryk added a comment -

        Thanks Tim - integrated now and confirmed fixed in other branches.

        Show
        Sam Hemelryk added a comment - Thanks Tim - integrated now and confirmed fixed in other branches.
        Hide
        Ankit Agarwal added a comment -

        no testing done as suggested

        Show
        Ankit Agarwal added a comment - no testing done as suggested
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Whoever decided one week was worth 14 days had really one bad idea. Anyway, the nightmare is over, so thanks for your, once again, amazing contributions. Many, many thanks!

        Now... disconnect, relax and enjoy the next days, yay!

        Closing...ciao

        Show
        Eloy Lafuente (stronk7) added a comment - Whoever decided one week was worth 14 days had really one bad idea. Anyway, the nightmare is over, so thanks for your, once again, amazing contributions. Many, many thanks! Now... disconnect, relax and enjoy the next days, yay! Closing...ciao

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: