Module: Course::Assessment::Submission::AnswersConcern

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/course/assessment/submission/answers_concern.rb

Instance Method Summary collapse

Instance Method Details

#from_question(question_id) ⇒ Object

Load the answers belonging to a specific question.

Keep this as a scope so the freshest data will be fetched from the database even if the CollectionProxy does not have the freshest data. Do not "optimise" by using select on the existing CollectionProxy or MCQ results will break.


15
16
17
# File 'app/models/concerns/course/assessment/submission/answers_concern.rb', line 15

def from_question(question_id)
  where(question_id: question_id)
end

#latest_answersObject

Scope to obtain the latest answers for each question for Course::Assessment::Submission.


6
7
8
# File 'app/models/concerns/course/assessment/submission/answers_concern.rb', line 6

def latest_answers
  unscope(:order).select('DISTINCT ON (question_id) *').order(:question_id, created_at: :desc)
end