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) ⇒ ClustersHierarchy

Returns a new instance of ClustersHierarchy.



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

def initialize(clusterable)
  @clusterable = clusterable
end

Instance Method Details

#base_and_ancestorsObject

Returns clusters in order from deepest to highest group



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

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

  model
    .unscoped
    .where.not('clusters.id' => nil)
    .with
    .recursive(cte.to_arel)
    .from(cte_alias)
    .order(depth_order_clause)
end