decidim-proposals/app/models/decidim/proposals/proposal_vote.rb in decidim-0.0.2 vs decidim-proposals/app/models/decidim/proposals/proposal_vote.rb in decidim-0.0.3
- old
+ new
@@ -4,16 +4,18 @@
# 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