You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/models/exercise_question.rb

54 lines
1.5 KiB

6 years ago
#encoding: utf-8
class ExerciseQuestion < ApplicationRecord
belongs_to :exercise
belongs_to :shixun, optional: true
has_many :exercise_choices
has_many :exercise_answers
has_many :exercise_shixun_challenges
has_many :exercise_shixun_answers
has_many :exercise_answer_comments
has_many :exercise_standard_answers
6 years ago
scope :insert_question_ex, lambda {|k| where("question_number > ?",k)}
scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
5 years ago
# scope :next_exercise, lambda {|k| where("question_number > ?",k).first}
# scope :last_exercise, lambda {|k| where("question_number < ?",k).last}
after_destroy :destroy_questions_relations
def destroy_questions_relations
exercise_choices.destroy_all
exercise_shixun_challenges.destroy_all
end
6 years ago
def question_type_name
case self.question_type
when 0
"单选题"
when 1
"多选题"
when 2
"判断题"
when 3
"填空题"
when 4
"简答题"
when 5
"实训题"
end
end
#获取问题的全部标准答案
def get_standard_answer_ids
exercise_standard_answers.pluck(:exercise_choice_id)
end
def get_standard_answer_text
exercise_standard_answers.pluck(:answer_text)
end
end