Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-30689

get_question_options Field Mismatch in question_answers

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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:

      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...

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            timhunt 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
            timhunt 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
            timhunt Tim Hunt added a comment -

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

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

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

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

            no testing done as suggested

            Show
            ankit_frenz Ankit Agarwal added a comment - no testing done as suggested
            Hide
            stronk7 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
            stronk7 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:
                  Fix Release Date:
                  9/Jan/12