# Pastebin 3uhuq6EA sub combine_with_query { my ($self, $query) = @_; my ($voter_clause, $voter_args) = $self->voter_clause; my $sql = "EXISTS ( SELECT TRUE FROM vote WHERE $voter_clause AND vote.superseded = FALSE AND %s AND vote.edit = edit.id )"; my @votes = grep { looks_like_number($_) } @{ $self->sql_arguments }; my $no_vote_option = grep { $_ eq 'no' } @{ $self->sql_arguments }; if (@votes && $no_vote_option) { $query->add_where([ join(' OR ', sprintf($sql, 'vote.vote = any(?)'), sprintf("NOT $sql", 'TRUE') ), [ $voter_args, \@votes, $voter_args ] ]); } elsif (@votes && !$no_vote_option) { $query->add_where([ sprintf($sql, 'vote.vote = any(?)'), [ $voter_args, \@votes, ] ]); } elsif (!@votes && $no_vote_option) { $query->add_where([ sprintf("NOT $sql", 'TRUE'), [ $voter_args, ] ]); } }