Closure_tree Show archive.org snapshot lets your ActiveRecord models act as nodes in a tree data structure.
This promises a few improvements over the battle-tested ancestry Show archive.org snapshot gem, such as:
It has some more moving parts than ancestry though (see below).
It does not use a ancestry
column, but a parent_id
column plus an extra table per model:
add_column :users, :parent_id, :integer
create_table :user_hierarchies, id: false do |t|
t.integer :ancestor_id, null: false
t.integer :descendant_id, null: false
t.integer :generations, null: false
end
This is enough to implement common read-operations like "get all descendants" with a single SELECT
.