A Ruby gem for organizing ActiveRecord models into efficient tree structures using the materialized path pattern.
Ancestry is a Ruby gem that adds hierarchical tree functionality to ActiveRecord models. It solves the problem of organizing and querying nested data efficiently by using the materialized path pattern, storing parent-child relationships in a single database column.
Ruby on Rails developers who need to model hierarchical data (like categories, organizational charts, or nested comments) in their applications and want efficient tree operations without complex SQL.
Developers choose Ancestry for its balance of performance and simplicity—it avoids extra tables, provides intuitive scopes for tree navigation, and supports real ActiveRecord associations, making it easier to integrate than raw SQL or other tree gems.
Organise ActiveRecord model into a tree structure
Uses the materialized path pattern to enable single SQL queries for ancestors, descendants, and other tree relations, avoiding complex joins and improving performance.
Supports multiple ancestry formats, orphan strategies, depth caching, and real ActiveRecord associations, allowing customization for different database and application needs.
Provides built-in methods like 'build_ancestry_from_parent_ids!' and 'check_ancestry_integrity!' for easy migration from other gems and ensuring data consistency without manual SQL.
Implements relations as ActiveRecord scopes and offers optional real associations, making it seamless to use with Rails conventions like eager loading and joins.
Due to B-tree index constraints, the ancestry column can store only up to 2704 characters, limiting maximum tree depth to 900 nodes depending on ID length, as noted in the README.
Ancestry has strict version compatibility with Rails (e.g., version 6.0 supports Rails 7.0 through 8.1), which can complicate upgrades and require careful version management.
The default :ruby update strategy triggers callbacks for each descendant when moving nodes, which may not scale well for large trees, though a :sql strategy is PostgreSQL-only.
Track changes to your rails models
A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models.
Easy activity tracking for models - similar to Github's Public Activity
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.