Class: Clusters::ClustersHierarchy

Inherits:
Object
  • Object
show all
Defined in:
app/models/clusters/clusters_hierarchy.rb

Constant Summary collapse

DEPTH_COLUMN =
:depth

Instance Method Summary collapse

Constructor Details

#initialize(clusterable, include_management_project: true) ⇒ ClustersHierarchy

Returns a new instance of ClustersHierarchy.


7
8
9
10
# File 'app/models/clusters/clusters_hierarchy.rb', line 7

def initialize(clusterable, include_management_project: true)
  @clusterable = clusterable
  @include_management_project = include_management_project
end

Instance Method Details

#base_and_ancestorsObject

Returns clusters in order from deepest to highest group


13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/clusters/clusters_hierarchy.rb', line 13

def base_and_ancestors
  cte = recursive_cte
  cte_alias = cte.table.alias(model.table_name)

  model
    .unscoped
    .where('clusters.id IS NOT NULL')
    .with
    .recursive(cte.to_arel)
    .from(cte_alias)
    .order(depth_order_clause)
end