class Survey < ActiveRecord::Base has_many :questions, :dependent => :destroy has_many :answers, through: :questions accepts_nested_attributes_for :questions, allow_destroy: true validates :title, presence: true validates :description, presence: true validates :creator_uid, presence: true def has_answers if answers.count > 0 return true end return false end enum visibility: { Public: 0, Protected: 1, Private: 2 } end