Sha256: d52ff741922e750751d1bdc6b49d6a58e959bb2ab2ab8618abb9536664132a81

Contents?: true

Size: 945 Bytes

Versions: 1

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    class SumOfMembershipWeight < Decidim::Query
      def initialize(relation)
        @relation = relation
      end

      def query
        relation
          .select(
            questions[:id].as("question_id"),
            questions[:title].as("question_title"),
            responses[:title],
            votes_count
          )
          .group(
            questions[:id],
            questions[:title],
            responses[:title]
          )
          .order(responses[:title])
      end

      private

      attr_reader :relation

      def questions
        Decidim::Consultations::Question.arel_table
      end

      def responses
        Decidim::Consultations::Response.arel_table
      end

      def votes_count
        field = Ponderation.arel_table[:weight]
        VotesCountAggregation.new(field, "votes_count").to_sql
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-action_delegator-0.8.1 app/queries/decidim/action_delegator/sum_of_membership_weight.rb