allows querying for a proposal's votes

This commit is contained in:
rgarcia
2017-12-15 19:21:02 +01:00
parent cec48c72ef
commit 56945d9bbe
3 changed files with 21 additions and 12 deletions

View File

@@ -1,6 +1,17 @@
ActsAsVotable::Vote.class_eval do
include Graphqlable
belongs_to :signature
scope :public_for_api, -> do
where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or
(votes.votable_type = 'Proposal' and votes.votable_id in (?)) or
(votes.votable_type = 'Comment' and votes.votable_id in (?))},
Debate.public_for_api.pluck(:id),
Proposal.public_for_api.pluck(:id),
Comment.public_for_api.pluck(:id))
end
def self.for_debates(debates)
where(votable_type: 'Debate', votable_id: debates)
end