class PollQuestion < ApplicationRecord

  belongs_to :poll
  has_many :poll_answers, :dependent => :destroy
  attr_accessor :question_answers, :question_other_anser
  has_many :poll_votes, :dependent => :destroy

  scope :ques_count, lambda {|k| where("question_type = ?",k)}
  scope :ques_necessary, -> {where("is_necessary = ?",1)}
  scope :insert_question, lambda {|k| where("question_number > ?",k)}
  scope :next_poll, lambda {|k| where("question_number > ?",k).first}
  scope :last_poll, lambda {|k| where("question_number < ?",k).last}

  def question_type_name
    case self.question_type
    when 1
      "单选题"
    when 2
      "多选题"
    when 3
      "主观题"
    when 4
      "多行主观题"
    end
  end
end