Sha256: e72f9721b0d9435f827bd94a01d40229c0f67a5d0bf461a374a3dc5e7156f4c9

Contents?: true

Size: 1021 Bytes

Versions: 4

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    class SumOfMembershipWeight < Rectify::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 authorizations
        Decidim::Authorization.arel_table
      end

      def votes_count
        field = Arel.sql("membership_weight")
        VotesCountAggregation.new(field, "votes_count").to_sql
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-action_delegator-0.6.0 app/queries/decidim/action_delegator/sum_of_membership_weight.rb
decidim-action_delegator-0.5.0 app/queries/decidim/action_delegator/sum_of_membership_weight.rb
decidim-action_delegator-0.4.1 app/queries/decidim/action_delegator/sum_of_membership_weight.rb
decidim-action_delegator-0.4 app/queries/decidim/action_delegator/sum_of_membership_weight.rb