Sha256: 2db1f94dd1fff5e6b431b044662c3dc8bc7aeacd7f010d0d2631ec86c6cc26c0

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    # This query object replaces the ActiveRecord association we would have between the Vote and
    # Delegation models. Unfortunately we can't use custom foreign keys on both ends of the
    # association so this aims to replace `delegation.votes`.
    class DelegationVotes < Decidim::Query
      def query
        Delegation.joins(
          delegations.join(votes).on(vote_author_eq_granter).join_sources
        )
      end

      private

      def votes
        Decidim::Consultations::Vote.arel_table
      end

      def delegations
        Delegation.arel_table
      end

      def vote_author_eq_granter
        votes[:decidim_author_id].eq(delegations[:granter_id])
      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/delegation_votes.rb