Newer
Older
dmpopidor / app / models / question_option.rb
@Gavin Morrice Gavin Morrice on 19 Jul 2018 771 bytes Remove Rails 3 attr accessible from models (#1691)
class QuestionOption < ActiveRecord::Base
  ##
  # Associations
  belongs_to :question
  has_and_belongs_to_many :answers, join_table: :answers_question_options


  validates :text, :question, :number, presence: {message: _("can't be blank")}

  scope :by_number, -> { order(:number) }
  ##
  # deep copy the given question_option and all it's associations
  #
  # @params [QuestionOption] question_option to be deep copied
  # @return [QuestionOption] the saved, copied question_option
  def self.deep_copy(question_option)
    question_option_copy = question_option.dup
    question_option_copy.save!
    return question_option_copy
  end

  def deep_copy(**options)
    copy = self.dup
    copy.question_id = options.fetch(:question_id, nil)
    return copy
  end
end