Download the PHP package yii2-extensions/nested-sets-behavior without Composer
On this page you can find all versions of the php package yii2-extensions/nested-sets-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yii2-extensions/nested-sets-behavior
More information about yii2-extensions/nested-sets-behavior
Files in yii2-extensions/nested-sets-behavior
Package nested-sets-behavior
Short Description yii2-extension
License BSD-3-Clause
Informations about the package nested-sets-behavior
Nested sets behavior
A powerful behavior for managing hierarchical data structures using the nested sets pattern in Yii ActiveRecord models.
Efficiently store and query tree structures like categories, menus, organizational charts, and any hierarchical data with high-performance database operations.
Features
- ✅ Efficient Tree Operations - Insert, move, delete nodes with automatic boundary management.
- ✅ Flexible Queries - Find ancestors, descendants, siblings, leaves, and roots.
- ✅ Multiple Trees Support - Manage multiple independent trees in the same table.
- ✅ Query Optimization - Single-query operations for maximum performance.
- ✅ Transaction Safety - All operations are wrapped in database transactions.
- ✅ Validation & Error Handling - Comprehensive validation with clear error messages.
Database support
Quick start
Installation
How it works
The nested sets model is a technique for storing hierarchical data in a relational database. Unlike adjacency lists (parent_id approach), nested sets enable efficient tree operations with minimal database queries.
- Creates root nodes using the nested sets pattern with
lft
,rgt
, anddepth
fields. - Manages hierarchy automatically when inserting, moving, or deleting nodes.
- Optimizes queries using boundary values for efficient tree traversal.
- Supports transactions to ensure data integrity during complex operations.
Why nested sets?
- Fast queries: Get all descendants with a single query (
lft BETWEEN parent.lft AND parent.rgt
). - Efficient tree operations: No recursive queries needed for tree traversal.
- Automatic maintenance: Left/right boundaries are calculated automatically.
- Depth tracking: Easy to limit query depth or build breadcrumbs.
Database setup
The package includes ready-to-use migrations for creating the necessary database structure.
Quick setup (Recommended)
-
Configure console application:
- Run migrations:
Alternative: Direct migration execution
Table structures created
Single tree (m250707_103609_tree.php
). Creates a tree
table for single hierarchical structure.
Multiple trees (m250707_104009_multiple_tree.php
). Creates a multiple_tree
table for multiple independent trees.
Basic Configuration
Add the behavior to your ActiveRecord model.
Basic Usage
Creating and building trees
Querying the tree
Moving nodes
Deleting nodes
Query builder integration
Add query behavior for advanced tree queries.
Now you can use enhanced queries.
Documentation
For detailed configuration options and advanced usage.
- 📚 Installation Guide
- ⚙️ Configuration Reference
- 💡 Usage Examples
- 🧪 Testing Guide
Quality code
Our social networks
License
Fork
This package is a fork of https://github.com/creocoder/yii2-nested-sets with some corrections.