# 学生试题答题记录
class ExerciseAnswer < ApplicationRecord
  #学生答题
  belongs_to :user
  belongs_to :exercise_question
  belongs_to :exercise_choice, optional: true
  has_many :exercise_answer_comments, :dependent => :delete_all

  scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)}
  scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)}
  scope :exercise_no_full_scores, lambda { |score| where("score > 0.0 AND score < ?",score)}
  scope :exercise_answer_is_right, -> {where("score > ?",0.0)}  #判断答案是否正确，根据分数总和大于0
  scope :score_reviewed, lambda {where("score >= ?",0.0)}   #是否评分,用于判断主观题的
  scope :by_user, lambda { |user_ids| where(user: user_ids) }

  validates :answer_text, length: { maximum: 5000, too_long: "不能超过5000个字符" }

end