forgeplus/app/models/vote_option.rb

12 lines
291 B
Ruby

class VoteOption < ApplicationRecord
belongs_to :vote
has_many :user_vote_options, dependent: :destroy
has_many :users, through: :user_vote_options
validates :title, presence: true
def self.selected?(option, user)
option.user_vote_options.exists?(user_id: user.id)
end
end