Class: Decidim::Assemblies::ParentAssembliesForSelect
- Inherits:
-
Query
- Object
- Query
- Decidim::Assemblies::ParentAssembliesForSelect
- Defined in:
- app/queries/decidim/assemblies/parent_assemblies_for_select.rb
Overview
This query filters assemblies that can be assigned as parents for an assembly.
Class Method Summary collapse
-
.for(organization, assembly) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
Instance Method Summary collapse
-
#initialize(organization, assembly) ⇒ ParentAssembliesForSelect
constructor
Initializes the class.
-
#query ⇒ Object
Finds the available assemblies.
Constructor Details
#initialize(organization, assembly) ⇒ ParentAssembliesForSelect
Initializes the class.
13 14 15 16 |
# File 'app/queries/decidim/assemblies/parent_assemblies_for_select.rb', line 13 def initialize(organization, assembly) @organization = organization @assembly = assembly end |
Class Method Details
.for(organization, assembly) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
8 9 10 |
# File 'app/queries/decidim/assemblies/parent_assemblies_for_select.rb', line 8 def self.for(organization, assembly) new(organization, assembly).query end |
Instance Method Details
#query ⇒ Object
Finds the available assemblies
Returns an ActiveRecord::Relation.
21 22 23 24 25 26 27 |
# File 'app/queries/decidim/assemblies/parent_assemblies_for_select.rb', line 21 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 |