stefankroes/ancestry

Organise ActiveRecord model into a tree structure

View on GitHub ↗Jump to charts ↓

Summary Information

Updated 59 minutes ago
Added to GitGenius on September 17th, 2026
Created on October 16th, 2009
Open Issues & Pull Requests: 31 (+0)
GitHub issues: Enabled
Number of forks: 473
Total Stargazers: 3,879 (+0)
Total Subscribers: 45 (+0)

Repository Insights (GitGenius)

Median issue/PR response: 19.9 days
Mean response time: 492.1 days
90th percentile: 1466.8 days
Tracked items: 44

Most active contributors

Sign in to see contributor activity.

Charts & Analytics

Fetching additional details & charts...

Issue Activity (beta)

Open issues: 7
New in 7 days: 0
Closed in 7 days: 0
Avg open age: 1,348 days
Stale 30+ days: 7
Stale 90+ days: 5

Recent activity

Opened in 7 days: 0
Closed in 7 days: 0
Comments in 7 days: 0
Events in 7 days: 0

Top labels

  • features (4)
  • questions (2)
  • bug (1)

Most active issues this week

No issue events were indexed in the last 7 days.

Detailed Description

Ancestry is a Ruby gem that organizes ActiveRecord models into a tree structure using the materialized path pattern.

The gem solves the problem of managing hierarchical data in relational databases by storing each record's ancestor chain in a single column rather than requiring separate tables or complex recursive queries. This materialized path approach enables single-query reads for any tree relation—ancestors, descendants, siblings, children, and leaves—using a btree index on that column. Moving a node in the tree only requires updating its descendants, not the entire tree structure.

Teams building Rails applications with hierarchical data should consider Ancestry if they need efficient tree operations on a single database node. The gem suits projects where you want to avoid the complexity of additional junction tables or the performance overhead of recursive queries. It provides real ActiveRecord associations like `belongs_to :parent` and `has_many :children` with eager loading support, depth caching, counter caches, and multiple strategies for handling deleted nodes. The tool supports single-table inheritance, allowing all classes to be returned from scopes unless explicitly filtered.

The project maintains active development with regular updates to its codebase. The maintainers respond to issues and pull requests, indicating ongoing engagement with the community. Documentation is comprehensive, covering configuration options, database setup, and advanced features like integrity checking and restoration. The gem has established itself as a stable solution with benchmarking data available to help developers understand its performance characteristics relative to other tree-structure approaches.