Sha256: 07289489427a7356a84d7102c8a24063ff8ff7ff41c1d3ba5f1b68e373c77112
Contents?: true
Size: 833 Bytes
Versions: 13
Compression:
Stored size: 833 Bytes
Contents
# frozen_string_literal: true module Decidim module Proposals # A proposal can include a vote per user. class ProposalVote < ApplicationRecord belongs_to :proposal, foreign_key: "decidim_proposal_id", class_name: Decidim::Proposals::Proposal, counter_cache: true belongs_to :author, foreign_key: "decidim_author_id", class_name: Decidim::User validates :proposal, :author, presence: true validates :proposal, uniqueness: { scope: :author } validate :author_and_proposal_same_organization private # Private: check if the proposal and the author have the same organization def author_and_proposal_same_organization return if !proposal || !author errors.add(:proposal, :invalid) unless author.organization == proposal.organization end end end end
Version data entries
13 entries across 13 versions & 2 rubygems