Questions tagged [nested-sets]
The nested set model is a particular technique for representing nested sets (also known as trees or hierarchies) in relational databases.
389
questions
-3
votes
0
answers
56
views
Nested set model to flatten php array
I am currently using the Craft CMS, which is based on the Yii2 framework. The nested set behaviour is an approach to store hierarchical data in relational databases.
For this, the Craft CMS uses the ...
0
votes
0
answers
21
views
Read .csv file into a multidemensional array for nested set
I have a problem with converting a csv file into a multidimensional array.
Source file:
id,category,parent_id
1,Электроника
2,Бытовая техника
3,Телевизоры,1
4,Компьютеры,1
5,Телевизоры Sony,3
6,...
0
votes
1
answer
39
views
When I am building nested sets, how do I get the right hand value of a non-leaf node
I'm trying to use a non-recursive depth-first-search approach to read directories and build nested sets. I need to assign left, right, and depth values to the path of the given directory(Files at the ...
0
votes
0
answers
49
views
How to optimize update statement
I am maintaining the Mike Hillyer Hierarchical Data in MySQL.
Q) How to optimize the update statement below. It will take average about 500 Milliseconds
update AGENCY_TREE set RGT = RGT - 2 where RGT ...
0
votes
0
answers
32
views
Which tree strategy to choose that saves sibling position?
Within a node, when the position of the children matters, which tree pattern (Adjacency List, Materialized Path, Nested Set, Closure Table, etc...) adopt to store and fetch the whole tree ordered by ...
0
votes
0
answers
62
views
MySQL sorting by max child date
I have a table with nested children. I'm trying to fetch a list of parents sorted by the most recent child, when available, otherwise the parent's created date. My query seemed to work at first, but ...
0
votes
0
answers
59
views
Using lazychaser / laravel-nestedset, parent_id column is set to null after saving model
I'm using nested set version 6.0.0 on laravel v7.30.4, I added columns to migration:
Schema::table('companies', function (Blueprint $table) {
$table->nestedSet();
});
And this ...
0
votes
1
answer
158
views
Nested set tree view data structure using with recursing and traversal techniques in MongoDB or JavaScript
Hey I'm trying to implement nested drag&drop within re-order sequencesin my MERN app. I working to find ideal approach for mongodb data model and implement to Lexicographic order or linked lists ...
0
votes
2
answers
51
views
How to stream through a Set<Set<Integer>> and put it into a HashMap as the value?
I have a Set Set:
Set<Set<Integer>> nestedSet = Set.of(Set.of(1, 9), Set.of(0,2,4), Set.of(14,1), Set.of(2,23,13), Set.of(14,22));
What i want to archive, is to stream through the ...
0
votes
2
answers
61
views
Why in my nested set hierarchy is my HAVING clause not comparing int values properly?
I'm modeling a category hierarchy in postgres using the nested set model as explain here. I am using a query to find the immediate subordinates of a node which is explained below in an excerpt from ...
1
vote
1
answer
84
views
F# How create tree from nested sets?
I have nested sets data from my db and need transform this to tree data structure:
type Item = {
Id: int
Left: int
Right: int
Level: int
}
type Items = Item list
type Tree = {Parent: ...
0
votes
0
answers
307
views
How we can find the level of a node in a tree using kalnoy/nestedset package | Laravel | nestedset
I am working on a Laravel application where I used kalnoy/nestedset package to make the tree structure for color categories. Now I want to know the level of the node related to the tree.
For example
...
-1
votes
1
answer
82
views
How to pass Controller data value in nestedset custom function in Laravel blade file
Find below the controller code and blade file code,
Tested & Working
Controller Code:
$nodes = Category::get()->toTree();
Blade File Code
Returning Value = 6 {{$data->category_id}}
I need ...
3
votes
2
answers
531
views
I get this error when delete object in nested in nestedset in laravel8
i get this error when delete object in nested in nestedset in laravel
"Declaration of Kalnoy\Nestedset\BaseRelation::getRelationCountHash() should be compatible with Illuminate\Database\Eloquent\...
1
vote
1
answer
81
views
Nested Set SQL Query to retrieve the first ancestor of each node
i have a Nested Set Tree and i am searching for an SQL query to retrieve the first ancestor of each node.
I will always get the root node or a list of all ancestors.
See: Nested Set Query to retrieve ...
0
votes
1
answer
199
views
Generating a Nested Set Model from a POJO
I have been playing around with some Nested Set Models (NSM). One thing I wanted to do is to be able to generate a NSM from a given JavaScript object.
For example, given the following object:
var ...
0
votes
0
answers
1k
views
Reordering nested set tree with Gedmo Tree
I'm managing categories with (Atlantic18/DoctrineExtensions) Gedmo Nested Set Tree strategy in Symofny4 application.
I need to reorder the existing tree passing an array of rearranged categories to ...
2
votes
1
answer
260
views
Recursive CTE while Parent Id not in a List
I have the following Nested Set
That results in this tree
1 -
|---- 2 -
| |---- 4 -
| |---- 7
| |---- 8
|----10 -
|---- 9
3 -
|----...
1
vote
1
answer
718
views
How to efficiently insert an array as nested set model with Laravel/PHP and MySQL
I am using this package to handle hierarchy data in Laravel: https://github.com/lazychaser/laravel-nestedset
Their is an implemented functionality which provides the opportunity to create new data ...
0
votes
0
answers
172
views
Find set of all parents in chain for multiple tips in an SQL nested set heirarchy
I have a large bifurcating hierarchy of 4 million nodes (2 million tips), organised as a nested set in an mySQL table (i.e. with rgt and lft positions defined for each node). I want an efficient way ...
1
vote
0
answers
104
views
SQL hierarchical document with nested sets
i try to create the sql tables and statements for my scenario. I use mySQL.
I have a standard hierarchical structure for documents but the structure of a specific document for a client can be ...
0
votes
1
answer
890
views
How to calculate the amount of each ingredient?
I'm trying to solve a problem, where I need to calculate nutrition values of a recipe like a "My sandwich"
I have a database with "recipes" and "ingredients" and the amount needed in kg.
a recipe ...
0
votes
1
answer
33
views
repeating node names in nested set
I'm retrieving the paths of leafs and there is repeated leaf names in nested set. After executing query different paths where leaf name is repeated came joined together.
i tried to fix sql code but ...
1
vote
1
answer
288
views
laravel: how to check item availability in each category?
I use laravel-nestedset and I can get all categories and its children with this code:
code1:
$categories = $this->traverse(Category::defaultOrder()->get()->toTree(), null);
For checking ...
1
vote
1
answer
406
views
Ecto - counting nested associations recursively
I have the following schema:
defmodule MyApp.Folder do
use Enterprise.Web, :model
schema "folders" do
has_many(:contracts, MyApp.Contract)
has_many(:child_folders, MyApp.Folder, ...
1
vote
2
answers
63
views
How to access a variable saved in the store method?
I'm using nested set comments (Kalnoy package) in my project and I'm stuck at creating children comments. I created two different method for both type of comments.
Saving root comments works fine:
...
1
vote
1
answer
2k
views
Laravel: seeding a nested set table with Faker
I'm using Kalnoy/Nestedset and trying to seed my comments table using faker, but get "Array to string conversion" error.
The comment table looks like this:
Schema::create('comments', function (...
2
votes
1
answer
6k
views
laravel 5.7 nested sets
I tried to seed nested set with array with Laravel 5.7 and https://github.com/lazychaser/laravel-nestedset package but always getting :
Array to string conversion error when function gets to main ...
0
votes
0
answers
25
views
Nested-sets only for categories or for end-elements too?
Does nested-sets model suit only for categories/catalogs (e.g fruits, vegetables), or for end-elements too (such as apple, onion etc.)?
Let's imagine my website is selling fruits and vegetables, and ...
1
vote
1
answer
108
views
after_save callback of act_as_nested_set model lead to SystemStackError
I am using Rails 5.1.6
I have a model called Taxon using acts_as_nested_set. I have 4 levels of Taxons, the last level sub_category has an attribute holding names of all parents, I want to update the ...
0
votes
0
answers
200
views
nested set binary tree, query leftmost and rightmost nodes
I have a MySQL table storing a binary tree in a nested set model with some extra properties. The binary tree is neither full nor complete, so there may be nodes on the middle with only one child.
It ...
1
vote
1
answer
89
views
Import tree dynamically
Working with laravel-nested sets Baum's package and try to import tree into mysql database. Import data:
1. FirstLevelWord1 - SecondLevelWord1 - ThirdLevelWord1 - FourthLevelWord1
2. FirstLevelWord1 -...
0
votes
0
answers
315
views
Baum/Node - get descendants from more than one id
I can get descendants from one ID like this:
return $node = \App\Categories::where('id',41)
->first()
->getDescendants()->pluck('id');
I wonder if it's possible to get descendants of ...
1
vote
0
answers
270
views
Using Composite Primary Keys, Baum Nested Set Trait with Laravel Eloquent Models
I have a pretty specific issue here that I'm trying to work out, and I'm really not sure it's possible but I figured it's worth a shot.
I am using an Eloquent model to manage categories for FOUR ...
0
votes
0
answers
29
views
Better way to not have transaction fail if there is no left value to update? (Nested Set PHP/SQL - PDO)
tldr (short version): Is there a more efficient way to have my update left values query not fail and ruin a transaction if there are no left values to update?
Long Winded Version if need more info. ...
0
votes
1
answer
860
views
Flat nested set to nested structs in Go
Maybe its just late in the day and this is making my brain melt.
I'm trying to convert a flat list of nested sets into a multi-dimensional nested array.
I have a bunch of structured CMS entries as ...
0
votes
0
answers
2k
views
Render React component in nested list
If we write something like below in ItemsList component:
render(){
return(
<div>
<ul>
{this.props.items.map(item => <Item key={...
1
vote
1
answer
2k
views
Render React component recursively
I got an array of objects and need to recursively render every single object like unmarked list :
<ul>
<li>
</li>
</ul>
All data comes from server like simple JSON:
{
...
2
votes
2
answers
843
views
How to convert nested set into nested array in javascript?
There is following data.
[
{"no":1, "name":"ELECTRONICS", "depth":0},
{"no":2, "name":"TELEVISIONS", "depth":1},
{"no":3, "name":"TUBE", "depth":2},
{"no":4, "name":"LCD", "depth":2},
...
1
vote
2
answers
127
views
How to sort nested set elements by rating of root element?
Tree comment system implemented as simple nested set
+---------+-----------+---------+---------+-------+--------+
| id | parent_id | lft | rgt | depth | rating |
+---------+-----------+--...
4
votes
1
answer
2k
views
MySQL Subquery Looping for each row returned
This uses two queries and I like to get result for each rows returned in the first subquery that will run the second query, essentially this will act like a foreach loop. I hope there is someone who ...
1
vote
1
answer
215
views
Nested Sets - Bottom Up Approach
From the nested sets reference document written by Mike Hyller and other blogs, I could understand how hierarchies are being managed in RDBMS. I was also able to successfully implement the model for ...
0
votes
1
answer
1k
views
nested set save to database
I'm trying to implement jqTree with Laravel app.
Controller gets data and return view:
public function index()
{
$categories = Category::get(['id', 'name', '_lft', '_rgt', 'parent_id'])->toTree(...
0
votes
0
answers
236
views
Need advice on nested set database design
I want to develop a KPI system but have some trouble on database design
Before I start, let me higlight first the business requirement:
Parent can get all child KPI. For example from image below (...
0
votes
1
answer
72
views
How to calculate score based on closeness of two nodes in tree?
Let's say I have a tree of categories, where each node in the tree is stored as a row in the database. The approach taken is a nested set. A sample tree for a clothing store would be:
id | name ...
3
votes
3
answers
908
views
Materializing the path of Nested Set hierarchy in T-SQL
I have a table containing details on my company's chart of accounts - this data is essentially stored in nested sets (on SQL Server 2014), with each record having a left and right anchor - there are ...
0
votes
1
answer
300
views
Awesome nestset set ancestor class method
Awesome nested set includes an ancestors instance method:
https://github.com/collectiveidea/awesome_nested_set/wiki/Awesome-nested-set-cheat-sheet
@john = Group.where(name: "John").first
@tree = @...
0
votes
1
answer
158
views
Store a users traversal path through a nested hierarchy
I have a nested tree stored in Neo4j. Where each node can have a (n)-[:CHILD]->(c) relationship with other nodes. Allowing you to query the entire tree from a given node down with MATCH (n)-[c:...
3
votes
1
answer
161
views
SQL conditional variables in select query
I'm trying to write an SQL query that uses the Nested Interval Hierarchy database model.
--Given a parent Id, this query retrieves the position of the youngest child which can be inserted into the ...
0
votes
1
answer
451
views
SQL: Getting immediate subordinates of node in nested set
I'm using this article as a guide to create a database tree structure using the nested set model.
However, I can't get it to work: when I execute the following query:
SELECT node.name, (COUNT(parent....