Sha256: a9a92c27d2c8f255bea92598fc68b3ffcfa2d2910817ca375ae09861a0f0cd61
Contents?: true
Size: 1.1 KB
Versions: 34
Compression:
Stored size: 1.1 KB
Contents
# frozen_string_literal: true module Decidim module Assemblies # This query filters assemblies that can be assigned as parents for an assembly. class ParentAssembliesForSelect < Rectify::Query # Syntactic sugar to initialize the class and return the queried objects. def self.for(organization, assembly) new(organization, assembly).query end # Initializes the class. def initialize(organization, assembly) @organization = organization @assembly = assembly end # Finds the available assemblies # # Returns an ActiveRecord::Relation. def query available_assemblies = Assembly.where(organization: @organization).where.not(id: @assembly) return available_assemblies if @assembly.blank? available_assemblies.where.not(id: descendant_ids) end private def descendant_ids recursive_children(@assembly).flatten end def recursive_children(model) model.children.map do |child| [recursive_children(child), child.id] end end end end end
Version data entries
34 entries across 34 versions & 1 rubygems